[英]How would I click this href link in Selenium?
Here is the code: 这是代码:
<div class="padding">
<a href="javascript:FreshCoShowEFlyerOverlay()">
<img alt="Example" src="http://freshco.wpengine.com/wp-content/uploads/2015/05/week-flyer-left.jpg" height="158" width="280">
</a>
</div>
I am trying to click on the href. 我试图单击href。 I have tried this but it does not work: 我已经尝试过了,但是没有用:
driver.findElement(By.xpath("//href[text()='javascript:FreshCoShowEFlyerOverlay']")).click();
Use this: 用这个:
driver.findElement(By.xpath("//a[@href='javascript:FreshCoShowEFlyerOverlay']")).click();
Intead of: 插入:
driver.findElement(By.xpath("//href[text()='javascript:FreshCoShowEFlyerOverlay']")).click();
作为另一个变体:
driver.findElement(By.CssSelector("a[href*='FreshCoShowEFlyerOverlay']")).click();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.