As per the xpath you have shared as follows :
choices = driver.find_elements_by_xpath("//div[contains(.,'5') and [contains(@class, 'option')]]")$
You need to consider a few facts :
- The multiple conditions for selecting the
<div>
tag can't be within nested []
. Either you have to specify within one []
or within multiple []
s.
- The xpath shouldn't end with unwanted characters e.g
$
Solution
You can rewrite the xpath
in either of the following ways :
choices = driver.find_elements_by_xpath("//div[contains(.,'5') and contains(@class, 'option')]")
# or
choices = driver.find_elements_by_xpath("//div[contains(.,'5')][contains(@class, 'option')]")
//div[contains(.,'5') and contains(@class, 'option')]
– Expertism