元素当前不可交互,不能操作(selenium)
我试图使一个投注脚本,遵循鞅投注风格。我已经尝试了很多东西,比如引入等待时间和乱用css选择器,我得到了同样的结果。任何帮助将不胜感激。
结果:追溯(最后一次调用):File“C:\Users line 28,in bet_input.clear()元素当前不可交互,并且不能使用python操作
产品编号:
from undetected_chromedriver import Chrome, ChromeOptions
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
# Configure undetected ChromeOptions
options = ChromeOptions()
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_argument("--disable-infobars")
options.add_argument("--start-maximized")
# Create a new instance of the undetected Chrome driver
driver = Chrome(options=options)
# Open Chrome and navigate to the website
driver.get('https://rollbit.com/x-flip')
# Set initial bet
initial_bet = 0.50
current_bet = initial_bet
sleep(5)
# Main loop
while True:
wait = WebDriverWait(driver, 45)
# Find the input field for the bet amount and enter the current bet
bet_input = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.css-p16zna input[type="text"]')))
bet_input.clear()
bet_input.send_keys(str(current_bet))
# Find the button for Heads or Tails and click it
bet_button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'button.css-ah57p3')))
bet_button.click()
# Wait for the result
sleep(10) # Or however long it typically takes for a round to complete
# Check the result
# If we won, reset the bet to the initial amount; if we lost, double the bet
if 'You won' in result:
current_bet = initial_bet
else:
current_bet *= 2```
1条答案
按热度按时间ao218c7q1#
你应该将bet_input css选择器修改为:
以便选择类的子元素,在本例中,该子元素是输入