我有个css选择器
#block-a4e7-et-lists-a4e7-et-lists-content > div > div > div.row > div.col-md-9.col-sm-12.col-lg-9.col-xs-12 > div > div.a4e7-fw-pagination > div:nth-child(5)
在网页上
在…
但是,即使经过长期的挣扎,我仍然无法使用python中selenium的driver.find_element_by_css_selector()函数来访问它。
你能帮我做这个吗?
最佳安打
发布于 2017-05-10 09:54:40
选择器本身太脆弱,因为:
col-xs-12 ),这些类通常过于宽泛,并且更有可能被更改。相反,我使用以下CSS选择器:
.content .a4e7-fw-pagination > div:nth-child(5)您可能也遇到了时间问题--当您搜索元素时,元素还没有出现。解决这类问题的常见方法是使用显式等待。具体而言,在您的案例中,您可能有以下内容:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 10)
element = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, ".content .a4e7-fw-pagination > div:nth-child(5)")))https://stackoverflow.com/questions/43888900
复制相似问题