Reputation: 4608
in one of the web app that I am automating, I find that I came across to some elements that have no ID or class or anything associated, or associated dynamically and won't be able to capture, therefore I have to use link text, for example, "Canada", and then when I do
driver.FindElements(By.LinkText("Canada")).Count > 0 ,
I won't get a "True" although "Canada" is right there. Does anybody came across this before and have any idea why it is?
Thank you!
Upvotes: 1
Views: 2022
Reputation: 10094
Are you sure "Canada" is indeed in a <a>
tag ? By.LinkText
is meant to search for anchor text
You can certainly create a XPath to search By.xpath
. Something like "//*[contains(text(),'Canada')]" (this is the only xpath I can give you without knowing your HTML structure)
Upvotes: 1
Reputation: 875
Use
driver.switchTo().frame("Your LinkText Frame Name");
driver.FindElements(By.LinkText("Canada")).Count > 0 ;
and try.
I think it may work.
Upvotes: 2