9

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.

3
  • Please share the html code and what you tried Commented May 2, 2014 at 10:54
  • Hi Vaibhav, Did you find the solution for this issue? I am also having the same issue.Kindly let me know if you have the working solution. Provided answers have not worked for me till now. Thanks in advance. Commented Oct 24, 2016 at 9:35
  • see this stackoverflow.com/questions/49103753/… Commented May 13, 2020 at 21:43

3 Answers 3

6

Try with following:

driver.findElement(By.linkText("Add a New Credit Card")).click();
Sign up to request clarification or add additional context in comments.

1 Comment

In my case, the source code is <a href="javascript:;" onclick="openLocation('L_52')"> == $0. But when I do driver.findElement(By.linkText(" == $0")).click(), it returns an error saying no such element: Unable to locate element. Any help?
6

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();

Comments

0

CSS selector is faster than XPATH so you can try

driver.findElement(By.cssSelector("a.add-link")).click();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.