Reputation: 143
I've got just an issue with some basic understanding regarding xpath. I've read in the xpath documentation and searched here for some time now (and obviously I have just overseen some basics) but I just got lost with the following case.
<div class="foo">
<h1 class="title">TRANSFERS</h1>
</div>
I know that there are several ways to get the HELLOWORLD from my code using xpath. But what do I do if I just want to search the whole page to see if it contains "HELLOWORLD" anywhere?
Reading the documentation, I came to that statement which gives me an error message:
y = driver.find_element_by_xpath([contains(text()='TRANSFERS')])
File "<ipython-input-587-f5ff19bd101b>", line 1
y = driver.find_element_by_xpath([contains(text()='TRANSFERS')])
^
SyntaxError: expression cannot contain assignment, perhaps you meant "=="?
What am I missing here?
Upvotes: 1
Views: 62
Reputation: 735
Use this : Try to create a list with WEBELEMENTS named x and then :
x=driver.find_elements_by_xpath([contains(.,'TRANSFERS')]
this won’t cause an error even if it doesn’t find and anything and will just return an empty list Have fun ;)
Upvotes: 0
Reputation: 33384
Your xpath is wrong.
Try either of the following xpath
options to identify text of the node.
y = driver.find_element_by_xpath("//*[contains(text(),'TRANSFERS')]")
OR
y = driver.find_element_by_xpath("//*[contains(.,'TRANSFERS')]")
OR
y = driver.find_element_by_xpath("//*[text()='TRANSFERS']")
Upvotes: 1