Question

This is my source code :

<div class="emph a-center addCard"
Or 
<a class="add-link" href="javascript:;" onclick="gotoPaymentAddressForm()">Add a New Credit Card</a
</div>

I need to click "Add New Credit" card which open form on the same page. Unable to do this using Selenium.

Kindly advice.

Was it helpful?

Solution

Try with following:

driver.findElement(By.linkText("Add a New Credit Card")).click();

OTHER TIPS

You can also use following xpath codes:

driver.findElement(By.xpath("//a[@onclick='gotoPaymentAddressForm()']")).click();

or

driver.findElement(By.xpath("//a[contains(text(),'Add a New Credit Card')]")).click();

CSS selector is faster than XPATH so you can try

driver.findElement(By.cssSelector("a.add-link")).click();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top