Defining an element in Selenium 2 and it's not being clicked on
-
24-10-2019 - |
Question
I've got the folling HTML on a page I'm trying to test:
<div class="iconlist">
<p>
<a href="/login"><img src="http://blahblahblah/icon-facebook.png" alt=""
width="26"
height="26"/></a>
<a href="/login"><img src="http://blahblahblah/icon-twitter.png" alt=""
width="26"
height="26"/></a>
<a href="/login"><img src="http://blahblahblah/icon-yahoo.png" alt=""
width="26"
height="26"/></a>
<a href="/login"><img src="http://blahblahblah/icon-gmail.png" alt=""
width="26"
height="26"/></a>
</p>
</div>
I'm trying to click on each icon to verify it takes me to the login page.
I've tried the following code but it seems to just ignore it and it stays on the page.
WebElement logoFacebook = driver.findElement(By.cssSelector("img[src*='icon-facebook']")).click();
Any ideas as to why the click() doesn't click?
Solution
Might the problem be that you are expecting click() to return something?
Have you tried 'driver.findElement(By.cssSelector("img[src*='icon-facebook']")).click();' by itself?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow