There are a lot of methods I've tried for clicking on the link generated by the HTML bellow
<a class="btn btn--primary welcomePageButton" href="#/dispatchlist">
<span class="">View Dispatches/Invoices</span>
</a>
I've tried
driver.find_element_by_xpath("//a[contains(#href,'dispatchlist')]").click()
driver.find_element_by_link_text("View Dispatches/Invoices").click()
driver.find_element_by_partial_link_text("View Dispatches").click()
And in every case, I got NoSuchElementException.
Can you please guide me to solve this?
PS: I used the latest version of Google Chrome.
After trying a lot of xpaths, I decided to use JS snippets which worked like a charm
driver.execute_script("document.getElementsByClassName('btn')[0].click()")
However, thanks, everyone.
Related
I got a html page like this
<li class="class1 class2"></li>
but I try to find this selector by using
response.xpath('//li[#class="class1 class2"]')
I always got None.
I also try to run this code:
response.xpath('//li[#class="class1"]')
response.xpath('//li[#class="class1 class2"]')
Both return None
Who can tell me what's wrong?
Maybe I resolved but I don't understand. I found a phenomenon that I use DevTools on Chrome, that shows like this <li class="class1 class2"><\li>. But I use scrapy to crawl and return <li class="class1 class2 class3"><\li>
I encountered some phenomenon that the web page source code is different from the source code I crawled.
Main issue is your <li><\li> is not valid HTML like <li></li> and xpath should look like:
.//li[contains(#class, 'class1') and contains(#class, 'class2')]
May use a tool like xpather to check if a path works or not.
i am trying to automate couple of Selenium-TestNg scenarios from the website - http://ecommerce.saipratap.net/checkpersonaldetail.php
I was trying to click on the "continue "button, but it seems to be an image.
Below is the snippet of the code. How to write the xpath for the same?
tried using the xpath - //a[contains(#href,'checkoutshiping.php')], but it didnt work
<a href="checkoutshiping.php"> ==$0
<img src="images/continue.gif" border="0"
style="cursor:hand;"> ==$0
</a>
Are you sure the user is logged in? I see other set of tags when check the website.
Have you tried below xpath.
//*[.='Checkout']
Use - //a[#href = "checkoutshiping.ph"], its gonna find your button. I checked it on your website.
Here is example from your website
I'm using materialize 0.100.2 and have used multiple card-panels. Each card-panel has a button that opens a dropdown. The dropdown is same for every trigger. I searched for the solution and I even found a problem just similar to mine. But I did not understand the solution that was proposed. The problem and solution I found is can be seen on github on following link -
https://github.com/Dogfalo/materialize/issues/2051
My problem is like I import data from backend and I iterate card-panels up to the length of data I receive. I put the dropdown below this iteration so for it to be common for all the card-panels.
Consider 'actionLists' with the data.
<div class="card-panel" data-ng-repeat="actionItem in actionLists">
.....
<button class="dropdown-button btn btn-floating" data-activates="dropdown-example"><i class="material-icons">edit</i></button>
</div>
<div id="dropdown-example" class="dropdown-content">
....
</div>
Can you please help me out. I'm quite new to materialize. Thanks in advance.
Before anything else, I'd recommend updating to version 1.0 rc1.
There have been some changes since the 0.x versions.
Then you can have multiple dropdown-trigger element reference the same dropdown-content.
See https://materializecss.com/dropdown.html
I am a newbie to java and selenium webdriver. I am having an issue clicking an image. Below is the page source.
<a href="javascript:void(0);">
<span class="HomeButton" onclick="javascript:onBtnHomeClick();"/>
</a>
I tried below codes but did not work and still getting the Unable to locate element error.
driver.findElement(By.xpath("//a[#onclick='onBtnHomeClick()']")).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[#id='js_AppContainer']/div[2]/div[1]/div[1]/span"))).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("HomeButton"))).click();
I have to click the homebutton. Any help would be much appreciated
I don't know why By.className("HomeButton") didn't work but you have errors in the other two.
In driver.findElement(By.xpath("//a[#onclick='onBtnHomeClick()']")).click(); the tag for onclick is <span> not <a>. It also not onBtnHomeClick() but javascript:onBtnHomeClick();
driver.findElement(By.xpath("//span[#onclick='javascript:onBtnHomeClick();']")).click();
If you want to use onBtnHomeClick() use contains
driver.findElement(By.xpath("//span[contains(#onclick, 'onBtnHomeClick')]")).click();
Or
driver.findElement(By.cssSelector("onclick*='onBtnHomeClick'")).click();
And in wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[#id='js_AppContainer']/div[2]/div[1]/div[1]/span"))).click(); the <span> parent tag is <a>, not <div>
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[#id='js_AppContainer']/div[2]/div[1]/div[1]/a/span"))).click();
You simply need the correct locator IF your element will be eventually visible.
Xpath = "//span[contains(#class,'HomeButton') and contains(#onclick,'onBtnHomeClick')]"
Add wait as needed above exanmple, that should work.
Please don't make comments regarding why i posted a similar question. I have tried many things and nothing is working. Below is the HTML
<div id="businessSettingsColumn1">
<div class="sectionLink">
Business details
</div>
<div class="sectionLink">
Operating hours
</div>
<div class="sectionLink">
Closed dates
</div>
<div class="sectionLink">
Appointment notifications
</div>
I need to click the second link
I have tried
1) webdriver.findElement(By.partialLinkText("Operating hours")).click();
2)webDriver.get(mylement.findElement(By.tagName("a")).getAttribute("href"));
3)
List<WebElement> businessLinks= busCol.findElements(By.className("sectionLink"));
for(WebElement bLink :businessLinks) {
if(bLink.getText().contains("Operating hours")) {
bLink.findElement(By.tagName("a")).click();
}
}
4) Using the Action builder to move the mouse and then doing a click
Also when i did this 3 times in a row , my element got clicked
webdriver.findElement(By.partialLinkText("Operating hours")).click();
webdriver.findElement(By.partialLinkText("Operating hours")).click();
webdriver.findElement(By.partialLinkText("Operating hours")).click();
I am using Firefox version 25.0 and Selenium version 2.35.0. Funny thing though is when i do a sysout , the values get printed and when i try to get the url using webdriver I get "Element not found in the cache - perhaps the page has changed since it was looked up" .. its pretty much a static page with links only so i dont understand why i am not able to click it.. Any help will be much appreciated.
Can you try calling focus() on the element before you click on it?
This usually occurs because the element was there at some point, but then something happened and then it's no longer there for some reason. I encounter this frequently when a page makes AJAX calls for example.
Have you tried adding some waits so that selenium is sure that the element is ready?