Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
Python 我能';我找不到按钮元素来单击它_Python_Selenium_Web_Web Scraping - Fatal编程技术网

Python 我能';我找不到按钮元素来单击它

Python 我能';我找不到按钮元素来单击它,python,selenium,web,web-scraping,Python,Selenium,Web,Web Scraping,我试图点击“查看所有细节”按钮,从OpenTable中展开餐厅的细节,但我一直得到一个无元素的例外 每个结果链接都有target=''u blank'属性。这意味着,如果要单击链接详细信息页面,将在“新建”选项卡中打开。要处理“新建”选项卡上的元素,应切换到该选项卡: driver.get(url) current = driver.current_window_handle driver.find_element_by_css_selector('a.rest-row-name').click

我试图点击“查看所有细节”按钮,从OpenTable中展开餐厅的细节,但我一直得到一个无元素的例外


每个结果链接都有
target=''u blank'
属性。这意味着,如果要单击链接详细信息页面,将在“新建”选项卡中打开。要处理“新建”选项卡上的元素,应切换到该选项卡:

driver.get(url)
current = driver.current_window_handle
driver.find_element_by_css_selector('a.rest-row-name').click()
driver.switch_to.window([tab for tab in driver.window_handles if tab != current][0])
请注意,您还应等待按钮变为可点击:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC

wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//button[.="View all details"]'))).click()

您可以尝试执行此
驱动程序。按类名称(“7f28dfbb”2c55c63f a8e8f9b4“06bf3736”)查找元素[1]。单击()
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC

wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//button[.="View all details"]'))).click()