Claude Bastien
Claude Bastien

Reputation: 141

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. I have tried this but it does not work:

driver.findElement(By.xpath("//href[text()='javascript:FreshCoShowEFlyerOverlay']")).click();

Upvotes: 0

Views: 750

Answers (2)

LagiNatoRRR
LagiNatoRRR

Reputation: 181

As another variant:

driver.findElement(By.CssSelector("a[href*='FreshCoShowEFlyerOverlay']")).click();

Upvotes: 0

Saritha G
Saritha G

Reputation: 2608

Use this:

driver.findElement(By.xpath("//a[@href='javascript:FreshCoShowEFlyerOverlay']")).click();

Intead of:

driver.findElement(By.xpath("//href[text()='javascript:FreshCoShowEFlyerOverlay']")).click();

Upvotes: 2

Related Questions