1

Can anyone help how to click the below link using selenium

<a class=”btn btn-primary btn-large” href="target-URL">Submit</a>

I tried using below options

  1. linkText
  2. partialLinkText
  3. CssSelector
  4. contains - logic which checks the URL text
1
  • tony, is the given answers worked for u? Commented Mar 23, 2016 at 8:24

4 Answers 4

1

You can try:

driver.findElement(By.xpath("//a[contains@class,'btn '] and contains(@class, 'btn-large') and contains(text(), 'Submit')")).click()
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. It worked. But i changed the parenthesis driver.findElement(By.xpath("//a[contains(@class,'btn ') and contains(@class, 'btn-large') and contains(text(), 'Submit')]")).click();
1

Give full xpath

driver.findElement(By.xpath("html/body/a").click();

Can try with tag name

driver.findElement(By.tagName("a").click();

Comments

0

Try with below xpath:

driver.findElement(By.xpath("//a[@href='target-URL']").click();

Comments

0

In theory, this is just:

driver.findElment(By.linkText("Submit")).click();

But, I'm pretty sure you've already tried that. Check if the element is in iframe/frame. If yes, you need to switch to it and only then find the link element:

driver.switchTo().frame("frame_name_or_id");

To switch back in the main context, use defaultContent():

driver.switchTo().defaultContent();

1 Comment

I tried that it didn't work for me. I am using firefox webdriver

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.