我想點擊文字鏈接,不工作:硒 - 如何可靠地點擊文本?還沒完全解決
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("https://my.gumtree.com/login")
driver.find_element_by_name("username").send_keys(email)
driver.find_element_by_id("existingUser").click()
driver.find_element_by_id("fld-password").send_keys(password)
driver.find_element_by_xpath("//*[contains(text(), 'Continue')]").click() # works
driver.get("https://my.gumtree.com/postad")
driver.find_elements_by_xpath("//*[text()='For Sale']")[-1].click() # this now works, thanks
# driver.find_element_by_xpath("//*[contains(@span,'Appliances']").click() # this worked but I need the next line instead
driver.find_element_by_xpath("//span[text()[normalize-space()='Phones, Mobile Phones & Telecoms']]").click() # this does not work
driver.find_element_by_xpath("//span[text()[normalize-space()='Phones, Mobile Phones & Telecoms']]").click() # this does not work either
driver.find_element_by_xpath("//span[text()[normalize-space()='Mobile Phones']]").click()
driver.find_element_by_xpath("//span[text()[normalize-space()='Other']]").click()
HTML:
<li class="border-b is-parent" data-category-name="Appliances" data-category-url="kitchen-appliances" data-category-id="2485" data-category-children="true">
<span class="category-name">
<span class="category-list-control is-parent">
</span>
Appliances
</span>
</li>
我該怎麼辦錯了嗎?
文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字文字
任何一個鏈接的HTML代碼? –
<跨度類= 「BTN-縮進-ICN ICN-標籤TXT-孤兒從 - 米」> ::之前 出售 – Castle
嘗試這樣//跨度[含有(文本(),「對於銷售')] –