Reputation: 64
So i want to locate a text field element using xpath, my code used to look like this, and it worked :
element = driver.findElement(By.xpath("//input[(@id='login') or (@name = 'login')]"));
But i wanted to make sure that the driver picks a text field, so i changed it to this :
element = driver.findElement(By.xpath("//input[((@id='login') or (@name = 'login')) and (@type='text']"));
It didn't work, i searched for a solution but i found little to no information on using both OR & AND on xpath.
Thank you !
Upvotes: 0
Views: 104
Reputation: 182
please try this one:
element = driver.findElement(By.xpath("//input[(contains(@id,'login') or contains(@name,'login')) and contains(@type,'text')]";
Upvotes: 0
Reputation: 816
Below worked for me:
element = driver.findElement(By.xpath("//input[(@id='login' or @name='login') and @type='text']")
Upvotes: 1
Reputation: 588
I guess there is a typo on the last @type- it should have been @type= and also there is a missing )
from the same @type condition.
Below is the corrected code which I have tested.
element = driver.findElement(By.xpath("//input[((@id=\"login\") or (@name = \"login\")) and (@type=\"text\")]"));
Upvotes: 1