I'm looking for a solution with this small selenium script. The problem happens when on the list there are more than 1 occurence of the text. i'm looking for in with xpath command[contains(). Then script stops.
As you see on my script tried to use css selector (un-commented) but it not valid. I have seen some solution with regular expression with css selector with ^ and $ but i don't how it works.
EDIT: I'm looking to select only the third element "LIT" as you see there are thee times LIT inside de list which block the script.
Here is the snippet html
<div class="prodUnitCat">
<ul class="fixFacetZindex clearBoth" id="divChildrenCategoryFilter_0">
/ul>
<ul data-lvlcat="2">
<li data-idcat="1000015739"><span>ACCESSOIRES LITERIE</span> (9)</li>
<li data-idcat="1000015760"><span>ELEMENT DE LIT</span> (5)</li>
<li data-idcat="1000015773"><span>LIT</span> (9)</li>
<li data-idcat="1000015794"><span>LIT D'APPOINT</span> (2)</li>
</ul>
</div>
and here my code
prod = db.select(sql)
for record in prod:
cat1 = record[10]
cat2 = record[11]
cat3 = record[12]
cat4 = record[13]
# loading check
WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id(headerFieldID))
# cat selection
driver.find_element_by_xpath(u"//span[contains(text(),'" + cat1 +"')]").click()
driver.find_element_by_xpath(u"//span[contains(text(),'" + cat2 + "')]").click()
#driver.find_element_by_css_selector("span[contains('" + cat2 +"')]").click()
driver.find_element_by_xpath(u"//span[contains(text(),'" + cat3 + "')]").click()
driver.find_element_by_xpath(u"//div[@id=\"categContent\"]/div[4]/ul/li/span[contains(text(),'" + cat4 + "')]").click()
loginButtonElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(loginButtonXpath))
loginButtonElement.click()