Reputation: 21
I'm having an issue with using XPATH with the Or operator. (Using Selenium in Python)
R = driver.find_element(By.XPATH,"//* [contains(text(),'Word1')]" or "//* [contains(text(),'Word2')]")
Currently the code is only looking for Word1 and not Word2. Would like for it search for Word1 and if Word1 doesn't exist, look for Word 2.
I would appreciate any feedback.
Upvotes: 2
Views: 936
Reputation: 111491
This XPath,
//*[text()[contains(.,'Word1') or contains(.,'Word2')]
will select all elements that contain an immediate text node that contains the substring 'Word1'
or the substring 'Word2'
.
Upvotes: 2
Reputation: 193048
A much simpler expression would be:
R = driver.find_element(By.XPATH,"//*[contains(., 'Word1') or contains(., 'Word2')]")
Upvotes: 2