Reputation: 3
I am trying to select a menu item...though xpath validates well in Xpath checker, it does not work from WebDriver ...can someone help?
I get Unable to locate element: {"method":"xpath","selector":"//a[contains(text(),'Start Loan Process')]"}
HMTL looks something like this
<div class="bd">
<ul class="first-of-type">
<li id="yui-gen7" class="yuimenuitem first-of-type" groupindex="0" index="0">
<li id="yui-gen8" class="yuimenuitem" groupindex="0" index="1">
<li id="yui-gen9" class="yuimenuitem" groupindex="0" index="2">
<li id="yui-gen10" class="yuimenuitem" groupindex="0" index="3">
<li id="yui-gen11" class="yuimenuitem" groupindex="0" index="4">
<a class="yuimenuitemlabel" href="#">Start Loan Process</a>
Upvotes: 0
Views: 1411
Reputation: 21
I have had very little luck with using the Text()
part of the xpath. I would rather use the .Text
(C#) or .getText()
(java) method.
This is how i would write this in c#:
driver.FindElement(By.Xpath(".//*/a").Text.Contains("Start Loan Process");
The xpath part is of course debateable. It could also be: ".//div/li/a"
. You can use what you want.
Upvotes: 2
Reputation: 2021
On the other hand you can also try to use findElementsBy(By.classname("yuimenuitemlabel")) Get them to list of web elements and then filter it using webelement.getText() method.
Upvotes: 0