如何解决 Selenium 中的 ElementNotInteractableException Python
How to solve ElementNotInteractableException in Selenium Python
我正在使用 Firefox geckodriver。
我想加载一个页面并点击 "I want it too button"
其中有 id="J_cutBtn"
但我收到错误
Element <div id="J_cutBtn" class="cut-btn"> is not reachable by keyboard
我尝试添加向下滚动页面,还添加了等待对象可点击。
代码如下:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference("browser.privatebrowsing.autostart", True)
path="C:/Users/Gupta Niwas/Downloads/Programming/College Projects/SEM 4/PBL SEM 4/geckodriver-v0.20.0-win64/geckodriver.exe"
browser = webdriver.Firefox(firefox_profile=firefox_profile,executable_path=path)
browser.get("https://mobile.mi.com/in/24hrMadness/task/?activityId=15&taskId=1026420&goodsId=4181200024&mi_channel=Social&mi_source=copyurl&mi_campaign=24hrMadness")
print(browser.title)
browser.execute_script("window.scrollTo(0, 900)")
browser.implicitly_wait(1000)
WebDriverWait(browser,10).until(EC.element_to_be_clickable((By.ID,"J_cutBtn")))
drop_btn=browser.find_element_by_id("J_cutBtn")
drop_btn.send_keys(Keys.RETURN)
使用click()
:
drop_btn.click()
按钮不能与.send_keys(Keys.RETURN)
一起使用
我正在使用 Firefox geckodriver。 我想加载一个页面并点击 "I want it too button" 其中有 id="J_cutBtn"
但我收到错误
Element <div id="J_cutBtn" class="cut-btn"> is not reachable by keyboard
我尝试添加向下滚动页面,还添加了等待对象可点击。
代码如下:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference("browser.privatebrowsing.autostart", True)
path="C:/Users/Gupta Niwas/Downloads/Programming/College Projects/SEM 4/PBL SEM 4/geckodriver-v0.20.0-win64/geckodriver.exe"
browser = webdriver.Firefox(firefox_profile=firefox_profile,executable_path=path)
browser.get("https://mobile.mi.com/in/24hrMadness/task/?activityId=15&taskId=1026420&goodsId=4181200024&mi_channel=Social&mi_source=copyurl&mi_campaign=24hrMadness")
print(browser.title)
browser.execute_script("window.scrollTo(0, 900)")
browser.implicitly_wait(1000)
WebDriverWait(browser,10).until(EC.element_to_be_clickable((By.ID,"J_cutBtn")))
drop_btn=browser.find_element_by_id("J_cutBtn")
drop_btn.send_keys(Keys.RETURN)
使用click()
:
drop_btn.click()
按钮不能与.send_keys(Keys.RETURN)