我正在尝试滚动 this页。 向下滚动到页面底部后,我需要单击“显示更多”按钮,但我无法使用 selenium 找到它。
self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
self.driver.find_element_by_class_name('button load-more-button').click()
但是我得到一个InvalidSelectorException
最佳答案
使用下面的代码:
elem = self.driver.find_element_by_css_selector(".button.load-more-button[aria-controls$='set-latest']");
//this line will scroll down to make element visible
self.driver.execute_script("window.scrollTo(" + elem.getLocation().x + "," +(elem.getLocation().y- 100) + ");");
elem.click();
关于python - 使用 selenium 在 nytimes.com 上单击 "show more"按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37341667/