Reputation: 27
Is it possible to use linkText locator in this code
I used driver.findElement(By.linkText("welcome")).click();
But it didn't work. Please help....
<div class="back-to">
<a class="button blue" href="javascript:history.back()">welcome</a>
</div>
Upvotes: 0
Views: 477
Reputation: 4424
The linkText should work in this case. Or else try the below alternatives(and please provide sufficient implicit timeout to give selenium sufficent time to detect the element):
1. Using xpath
, to click on the element 'a' with exact innerHTML/text as 'welcome':
driver.findElement(By.xpath("//a[.='welcome']")).click();
2- Using JavascriptExecutor
to click on the element with exact innerHTML/text as 'welcome':
((JavascriptExecutor)driver).executeScript("arguments[0].click();", driver.findElement(By.xpath("//a[.='welcome']")));
3- Using partialLinkText
to click on the link with partial text 'welcome'
driver.findElement(By.partialLinkText("welcome")).click();
Upvotes: 1
Reputation: 12814
This Should be enough:
driver.find_element_by_xpath('//a[@class="button blue"]').click();
Upvotes: 0