簡體   English   中英

Python Selenium 錯誤:元素不可交互

[英]Python Selenium ERROR: element not interactable

這是我破解密碼游戲的代碼:最終它說密碼圈(容器)不可交互,我該如何解決這個問題?)

from time import sleep


driver = webdriver.Chrome()
driver.get('https://meduza.io/games/bud-hakerom-igra-meduzy')
xpath = driver.find_element_by_xpath
start_button = xpath('//*[@id="maincontent"]/div/div/div[2]/div[2]/div[3]/button')
start_button.click()
sleep(4)
driver.switch_to.frame('/embed/cows')
play_button = xpath('//*[@id="app"]/div/form/div[1]/div[1]/button')
play_button.click()
sleep(1)
first_container = xpath('//*[@id="app"]/div/div/div[1]/div[1]/div/div/span[1]')
second_container = xpath('//*[@id="app"]/div/div/div[1]/div[1]/div/div/span[2]')
third_container = xpath('//*[@id="app"]/div/div/div[1]/div[1]/div/div/span[3]')
fourth_container = xpath('//*[@id="app"]/div/div/div[1]/div[1]/div/div/span[4]')
for x in range(10):
    for y in range(10):
        for z in range(10):
            for t in range(10):
                first_container.send_keys(x)
                second_container.send_keys(y)
                third_container.send_keys(z)
                fourth_container.send_keys(t)```

找到元素時會發生 ElementNotInteractableException,但您無法與之交互。 您可以將它與 actionChains 一起使用

它的原因有很多:

元素不可見/未顯示元素在屏幕外元素在另一個元素后面或隱藏

找到下面的代碼,我已經用硬編碼值測試了這個:

driver.get('https://meduza.io/games/bud-hakerom-igra-meduzy')
xpath = driver.find_element_by_xpath
start_button = xpath('//*[@id="maincontent"]/div/div/div[2]/div[2]/div[3]/button')
start_button.click()
time.sleep(5)
driver.switch_to.frame('/embed/cows')
play_button = xpath('//*[@id="app"]/div/form/div[1]/div[1]/button')
play_button.click()
time.sleep(5)
first_container = xpath('//*[@id="app"]/div/div/div[1]/div[1]/div/div/span[1]')
second_container = xpath('//*[@id="app"]/div/div/div[1]/div[1]/div/div/span[2]')
third_container = xpath('//*[@id="app"]/div/div/div[1]/div[1]/div/div/span[3]')
fourth_container = xpath('//*[@id="app"]/div/div/div[1]/div[1]/div/div/span[4]')


for x in range(10):
    for y in range(10):
        for z in range(10):
            for t in range(10):
                actionChains = ActionChains(driver)
                actionChains.move_to_element(first_container).click().perform()
                actionChains.move_to_element(first_container).send_keys("2").perform()

                actionChains.move_to_element(second_container).click().perform()
                actionChains.move_to_element(second_container).send_keys("3").perform()

                actionChains.move_to_element(third_container).click().perform()
                actionChains.move_to_element(third_container).send_keys("3").perform()

                actionChains.move_to_element(fourth_container).click().perform()
                actionChains.move_to_element(fourth_container).send_keys("3").perform()

注意:請將以下導入添加到您的解決方案中

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.options import Options
import time
from selenium.webdriver.common.action_chains import ActionChains

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM