我如何在 Selenium 中单击此 href link?
How would I click this href link in Selenium?
代码如下:
<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();
作为另一种变体:
driver.findElement(By.CssSelector("a[href*='FreshCoShowEFlyerOverlay']")).click();
代码如下:
<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();
作为另一种变体:
driver.findElement(By.CssSelector("a[href*='FreshCoShowEFlyerOverlay']")).click();