[英]Python-Selenium "element not interactable"
我试图用硒填充数独,但每次都提出一个不可交互的元素
相关代码:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://sudokutable.com/')
driver.find_element_by_xpath('//*[@id="body_wrapper"]/main/section[2]/div[1]/div[2]/div[1]').send_keys('1')
我也尝试过,但结果相同:
sleep(1)
num = driver.find_element_by_xpath('//*[@id="body_wrapper"]/main/section[2]/div[1]/div[2]/div[1]')
num.click()
num.send_keys('1')
如果有人知道任何发送密钥的方法,我非常感谢
首先,我们需要关闭 Cookie 弹出窗口。
然后我们需要找到空单元格并尝试填充单元格。 空单元格可以通过svg
标签中的class
属性识别。
DOM when the cell is already filled
<div class="game-grid__cell" data-group="1" data-row="0" data-column="4">
<svg class="default" viewBox="0 0 72 72">
DOM when the cell is empty
<div class="game-grid__cell" data-group="0" data-row="0" data-column="1">
<svg class="" viewBox="0 0 72 72">
# Imports required:
from selenium.webdriver import ActionChains
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
driver.get("https://sudokutable.com/")
actions =ActionChains(driver)
wait = WebDriverWait(driver,30)
# Close Cookie pop-up
wait.until(EC.element_to_be_clickable((By.ID,"agree_cookies"))).click()
# Find empty cells and use indexing to fill them up
cell = driver.find_elements_by_xpath("//div[@class='game-grid__group'][1]/div/*[name()='svg' and @class='']")
actions.move_to_element(cell[0]).click().send_keys("1").perform()
试试这个而不是num.click()
:
driver.execute_script("arguments[0].click();", num)
要发送密钥,请使用:
driver.find_element_by_tag_name('body').send_keys('1')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.