Reputation: 117
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
Upvotes: 1
Views: 6318
Reputation: 57
Give full xpath
driver.findElement(By.xpath("html/body/a").click();
Can try with tag name
driver.findElement(By.tagName("a").click();
Upvotes: 1
Reputation: 328
You can try:
driver.findElement(By.xpath("//a[contains@class,'btn '] and contains(@class, 'btn-large') and contains(text(), 'Submit')")).click()
Upvotes: 1
Reputation: 2608
Try with below xpath:
driver.findElement(By.xpath("//a[@href='target-URL']").click();
Upvotes: 0
Reputation: 473863
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();
Upvotes: 0