Unable to locate element for a website - html

Unable to inspect search label in www.walmart.com website. Any help much appreciated.
tried using css , id , etc but nothing helped. All the below code i tried but it didn't helped.
driver.findElement(By.id("global-search-input")).sendKeys("asifalikhan786#gmail.com");
driver.findElement(By.xpath("//*[#id='global-search-input']")).sendKeys("dssss");
driver.findElement(By.cssSelector("input[placeholder = 'Search']")).sendKeys("adahadha");

I looked at the page's code and noticed that By.id cannot work, because the object you want to access has no id.
I suggest you to try this:
WebElement element = driver.findElement(By.className("eader-GlobalSearch-input"));
element.clear();
element.sendKeys("your text");

Related

Selenium not giving whats inside a class?

PATH = "D:\CDriver\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get('https://www.se.com/ww/en/about-us/careers/job-details/inside-sales-associate/006ZMV')
TITLE = driver.find_element_by_class_name('sdl-application-job-details__job-title')
print(TITLE)
driver.quit()
I have all the needed imports, I just wanted to leave them out.
When I run this the output SHOULD be: Inside Sales Associate
But instead it gives me this: <selenium.webdriver.remote.webelement.WebElement, the session and element code.
What do I need to do to make it print what it should print. I have tried by_tag_name('h1.sdl-application-job-details__job-title') but that gives the exact same.
There is a inbuilt title method available in Selenium. You can call that method on driver object not on web element.
Code :
driver.get('https://www.se.com/ww/en/about-us/careers/job-details/inside-sales-associate/006ZMV')
driver.title
print(driver.title)
or if you want to retrieve text inside any web element, you could probably do something like this :
class_value = driver.find_element(By.CSS_SELECTOR, "h1[class$='sdl-application-job-details__job-title']").text
print(class_value)
The find_element methods return web elements. Just pass print(TITLE.text)

Clicking checkbox for website with only div class available

HTML Code
<div class="_2yjv">
<input type="checkbox">
VBA Code
'Click check box
Dim cbox As Object
Set cbox = ie.document.getElementsByClassName("_2yjv")(0)
cbox.Click
Hi, I have been trying to put a check on a checkbox for a couple of hours now and have tried the following:
cbox.Click
cbox.DoubleClick
cbox.Value = True
cbox.Checked = True
cbox.Value = 1
cbox.Click and cbox.DoubleClick had no errors, but is not doing anything.
The rest shows errors. It's the only checkbox from a popup window.
I've been searching this forum and others but they usually have the name value on them, and I can only find those two lines from inspect element which points to the checkbox button. Would really appreciate any help on this. I'm new and still learning VBA. Thank you.
Thank you #Zwenn, cbox.FirstChild.Click did the trick.

adding imageurl to image element dynamically wont work

so iam trying to add a image i have saved on my project in image folder. But it dosent work
DirectCast(Customer.Items(0).FindControl("imageControl"), Image).ImageUrl = "~/images/IMG_1287.JPG"
DirectCast(Customer.Items(0).FindControl("imageControl"), Image).DataBind()
customer is the repeater html element the image element is in. I cant call the image element direct in the server code because the image element is inside a repeater element. So i have to use findcontrol method which works good. When i debugg the code i can se that it finds the right image element the problem is when i set the imageurl nothing seems to happen in the ui but i dont understand why can anybody help me please :)
<div>
<asp:Image ID="imageControl" Width="100%" Height="70%" runat="server"/>
</div>
To me it looks like you are not trying access controls within repeater in correct manner , it should be like :
If image is in header :
DirectCast(Customer.Controls[0].Controls[0].FindControl("imageControl"), Image).ImageUrl = "~/images/IMG_1287.JPG"
If image is in footer
DirectCast(Customer.Controls[Customer.Controls.Count - 1].Controls[0].FindControl("imageControl"), Image).ImageUrl = "~/images/IMG_1287.JPG"
Please have a look at this post for more details.
PS : Are you using vb ? cause i have used C# syntax, if yes change accordingly.

Unable to locate element (without Id) in webpage using selenium

I've been trying to access/locate the element shown in the image and have tried various methods. xpath, classname, css but keep getting the error that the element cannot be found. Can you help please ?
Attempt1
driver.find_element_by_class_name(".btn.btn-default").send_keys(os.getcwd() + "InputFiles/Error.png")
Error:
Attemp2:
driver.find_element_by_xpath("//div[#class='upload-btn__wrapper']").send_keys(os.getcwd() + "InputFiles/Error.png")
Error:
This xpath is supposed to work.
"//div[#class='upload-btn__wrapper']/button"
Hope this helps. Thanks.
Hope it help you. Let me know if you need further assistance.
driver.find_element_by_xpath("//div[#class='upload-btn__wrapper']")
I suggest to use below Xpath as it will rely on your Text, so any changes in text of the button will result a failure of the test, which makes perfect sense.
//button[normalize-space(text())='Choose image']
Also use explicit wait before performing any operations with that element.
new WebDriverWait(driver, time).until(ExpectedConditions.visibilityOf(By.xpath("//button[normalize-space(text())='Choose image']")));
WebElement chooseImageButton=driver.findElement(By.xpath("//button[normalize-space(text())='Choose image']"));
chooseImageButton.click();
Try the below solution as well :
driver.findElement(By.xpath("//div[contains(#class,'margin-bottom')]")).findElement(By.xpath("//div[contains(#class,'upload-btn__wrapper')]")).click();
Explanation : I am navigating from the parent div which is "margin-bottom" div class and reaching out to the child div which we want to locate, which is "upload-btn__wrapper".
Let me know, if this works out.
You can click on it with css selector also. Hope this will work for you.
driver.findElement(By.cssSelector(".btn.btn-default")).click();

Update panel in asp.net

I am using two update panel..in nested way.. can i use like this and also
in my project im using clientscript.RegisterScript along with update panel , its not giving any error but , my pop up is not being displayed when i click one item on grid. the pop up is in update panel which is inside (nested)..
can anyone help ???
Thank you
RegisterScript may not work well with updatepanel. use PageRequestManager.add_endRequest method to hook-up client script in this scenario.
if (window.Sys){
var prmx = window.Sys.WebForms.PageRequestManager.getInstance();
prmx.add_endRequest(function() {
alert('insert your code here...');
});
}
also make sure there is no javascript erros during page load.