Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 尝试单击按钮类型=";按钮“;使用python使用selenium_Html_Python 3.x_Selenium - Fatal编程技术网

Html 尝试单击按钮类型=";按钮“;使用python使用selenium

Html 尝试单击按钮类型=";按钮“;使用python使用selenium,html,python-3.x,selenium,Html,Python 3.x,Selenium,我想单击中的按钮。我尝试了几个代码,但失败了 HTML代码: <li data-id="page-2" class="_1eqazlr"> <button type="button" class="_1ip5u88" aria-label="Page 2" aria-busy="false"> <div class="_1bdke5s">2</div> </button></li> 除了上面的“路径”之外,我还尝试

我想单击中的按钮。我尝试了几个代码,但失败了

HTML代码:

<li data-id="page-2" class="_1eqazlr">
 <button type="button" class="_1ip5u88" aria-label="Page 2" aria-busy="false">
  <div class="_1bdke5s">2</div>
 </button></li>
除了上面的“路径”之外,我还尝试了几种不同的XPATH,如下所示:

path="//button[contains(@class,\"_lip5u88\") and contains(@aria-label,\"Page 2\")]"

path="//*[@id='reviews']/div/div/div/section/div[2]/div[3]/div/div/div/nav/span/div/ul/li[2]//button"

path="//button[@type='button']//following::div[text()='2']"

path='.//button[[@type="button" and normalize-space()="2"]'
出现如下错误:

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <button type="button" class="_1ip5u88" aria-label="Page 2" aria-busy="false">...</button> is not clickable at point (214, 871). Other element would receive the click: <div class="_10ejfg4u">...</div>
  (Session info: chrome=77.0.3865.90)

or 

selenium.common.exceptions.TimeoutException: Message: 

selenium.common.exceptions.element单击拦截异常:消息:元素单击拦截:元素。。。在点(214871)处不可单击。其他元素将收到单击:。。。
(会话信息:chrome=77.0.3865.90)
或
selenium.common.Exception.TimeoutException:消息:
你能帮我弄清楚吗?多谢各位

这应该有效:

driver.execute_script("""
  document.querySelector('[aria-label="Page 2"]').click()
""")

感谢您的及时回复,但它不起作用。它没有出错,但我无法进入第二页。我刚刚在driver.get(add)之后尝试了这段代码。你可能需要添加一个wait/time.sleep当我在你的代码前面加上time.sleep(5)时,它工作得非常好。非常感谢你!
driver.execute_script("""
  document.querySelector('[aria-label="Page 2"]').click()
""")