Defining an element in Selenium 2 and it's not being clicked on
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=""
开发者_JS百科 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?
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?
精彩评论