这是代码:
<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>
我正在尝试单击 href。我已经尝试过,但它不起作用:
driver.findElement(By.xpath("//href[text()='javascript:FreshCoShowEFlyerOverlay']")).click();
最佳答案
使用这个:
driver.findElement(By.xpath("//a[@href='javascript:FreshCoShowEFlyerOverlay']")).click();
而不是:
driver.findElement(By.xpath("//href[text()='javascript:FreshCoShowEFlyerOverlay']")).click();
关于java - 我如何在 Selenium 中点击这个 href 链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31512635/