im使用python 3.7.4,最新的selenium和geckodriver和Firefox 69.0.1版。
我试图简单地在Google主页上的“我感到幸运”按钮上使用click(),但出现了错误selenium.common.exceptions.ElementNotInteractableException: Message: Element <option> could not be scrolled into view
。
我尝试使用msg_box.location_once_scrolled_into_view
和get_element_by_class / id / name无效。这是代码:
from selenium import webdriver
import time
url = 'https://www.google.com'
driver = webdriver.Firefox()
driver.get(url)
time.sleep(4)
msg_box = driver.find_element_by_class_name('RNmpXc')
msg_box.location_once_scrolled_into_view
time.sleep(1)
msg_box.click()
什么会导致错误?
答案 0 :(得分:0)
消息
selenium.common.exceptions.ElementNotInteractableException:消息:无法将元素滚动到视图中。
表示当前无法选择。您的程序正在尝试与之交互,但是无法滚动到视图中。可能是程序正在尝试查找该元素,但是随后它(例如)“消失”(例如弹出或出现一个新按钮),因此无法滚动到视图中,因此无法单击。
您可以添加等待条件(当出现弹出窗口时),它会在弹出窗口消失后等待几秒钟(单击元素)。
msgBox02 = WebDriverWait(驱动程序,10)。直到(EC.element_to_be_clickable((By.ID,“ EXAMPLE”))) msgBox02.click()
注意:我添加了与RNmpXc相同的示例
答案 1 :(得分:0)
得出WebDriverWait
和presence_of_element_located
()
引出javascript executor
。但是,网络驱动程序单击按钮无效。
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
url = 'https://www.google.com'
driver = webdriver.Firefox()
driver.get(url)
element=WebDriverWait(driver,10).until(EC.presence_of_element_located((By.CLASS_NAME,'RNmpXc')))
driver.execute_script("arguments[0].click();", element)