這里是我在一個html頁面中的元素
< div class='test'>my text</div>
我試圖用我的Python的Selenium驅動程式檢索這個div的文本
。mytext = driver.find_element_by_xpath("//div[contains(@class, 'test')/text()]"/span>)
print mytext
但是沒有回傳任何東西
謝謝你this回傳"True"。
try。
driver.find_element_by_xpath("//div[@class='test']")
mystatus = "True"/span>
除了NoSuchElementException。
mystatus = "False"
但是這個回傳 "False"
。try:
driver.find_element_by_xpath("//div[@class='test']/text()")
mystatus = "True"/span>
except NoSuchElementException。
mystatus = "False"
uj5u.com熱心網友回復:
嘗試在Python中用.text獲得元素后的文本。
driver. find_element_by_xpath("//div[@class='test']").text
uj5u.com熱心網友回復:
輕微的調整:
//div[contains(@class, 'test')]/text()
你只是把最后的方括號放在了錯誤的地方。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/327102.html
標籤:
