如何解决在Dyanmic XPath中获取价值
number_of_selected_players = self.driver.find_element_by_xpath("/html[1]/body[1]/main[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[2]/div[4]/div[1]/div[1]/div[1]").value()
print(number_of_selected_players)
但是我最终收到此错误:
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html[1]/body[1]/main[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[2]/div[4]/div[1]/div[1]/div[1]"}
(Session info: chrome=85.0.4183.83)
我该如何解决此问题,或者您可以指出与此类似的问题,这样我就可以犯什么错误?
谢谢。
解决方法
您可以使用以下同级xpath命令获取“ 0/15”。
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
WebDriverWait(self.driver,50).until(
EC.presence_of_all_elements_located
((By.XPATH,'//h3[text()="Players Selected"]/following-sibling::div'))
)
number_of_selected_players = self.driver.find_element_by_xpath('//h3[text()="Players Selected"]/following-sibling::div').text
print(number_of_selected_players)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。