使用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')
然而,我需要它来为我正在做的事情的类名工作
任何帮助都将不胜感激
类名不支持空格,正如您在类名中看到的那样
paginate_button next
有一个空格如果您想继续相同的操作,您需要使用
CSS_SELECTOR
,下面的小改动应该适合您:您试图根据元素的“分部类属性”定位元素,而使用
find_element_by_class_name
定位元素需要准确的类属性值。可以使用css_选择器或XPath按部分属性值选择元素。
因此,您可以使用css_选择器
或
或XPath
或
相关问题 更多 >
编程相关推荐