【发布时间】:2021-06-24 16:21:47
【问题描述】:
使用 HTML:
<a class="paginate_button next" aria-controls="tabcc" data-dt-idx="7" tabindex="0" id="tabcc_next">Next</a>
我试图按类来选择“下一个”innerHTML。我正在尝试:
next_page = self.driver.find_element_by_class_name('paginate_button next')
和
next_page = WebDriverWait(self.driver, 20).until(
EC.presence_of_element_located((By.CLASS_NAME, "paginate_button next"))
)
但两者都报错:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".paginate_button next"}
(Session info: chrome=91.0.4472.114)
用 ID 做同样的想法似乎是有效的:
next_page = self.driver.find_element_by_id('tabcc_next')
但是,对于我正在做的事情,我需要它为类名工作。
任何帮助将不胜感激!
【问题讨论】:
标签: python selenium xpath css-selectors