Python 硒有时不';有时不要单击复选框

Python 硒有时不';有时不要单击复选框,python,python-3.x,selenium,selenium-webdriver,selenium-chromedriver,Python,Python 3.x,Selenium,Selenium Webdriver,Selenium Chromedriver,我对Selenium是新手,所以我制作了一个机器人来自动完成一些琐事,这样我就可以理解这个模块,这是一个很好的实践。有时.click()函数不起作用 我试过: from selenium import webdriver from time import * from data import * from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait f

我对Selenium是新手,所以我制作了一个机器人来自动完成一些琐事,这样我就可以理解这个模块,这是一个很好的实践。有时.click()函数不起作用

我试过:

from selenium import webdriver
from time import *
from data import *
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.common.exceptions import NoSuchElementException, StaleElementReferenceException
from winsound import *
import os
def AutoAnswer(self, answers_list, link):
    global i
    if i == 1:
        self.driver.get(link)
    # sends browser to first trivia
    # sets the variable to the current question so that the correct answer can be located through answer lists

self.current_question = (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="quizContainer"]/div[2]')))).text

#setting variables for boxes and their text values. The text can be corrolated to the button allowing the bot to click the correct answer
#/html//div[@id="quizContainer"]/div[@class="answersContainer"]/div[1]/span[@class="answerBox"]/a[@name="checkboxtag"]

for i in range(0, len(answers_list)):
    if answers_list[i]["question"] == self.current_question:
        self.current_answer = answers_list[i]["answer"]


self.xpath_1  = '//*[@id="quizContainer"]/div[3]/div[1]/span[1]/a'
self.text_1   = ((WebDriverWait(self.driver, 120)).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="quizContainer"]/div[3]/div[1]/span[2]')))).text


self.xpath_2  = '//*[@id="quizContainer"]/div[3]/div[2]/span[1]/a'
self.text_2   = ((WebDriverWait(self.driver, 120)).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="quizContainer"]/div[3]/div[2]/span[2]')))).text


self.xpath_3  = '//*[@id="quizContainer"]/div[3]/div[3]/span[1]/a'
self.text_3   = ((WebDriverWait(self.driver, 120)).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="quizContainer"]/div[3]/div[3]/span[2]')))).text


self.xpath_4  = '//*[@id="quizContainer"]/div[3]/div[4]/span[1]/a'
self.text_4   = ((WebDriverWait(self.driver, 120)).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="quizContainer"]/div[3]/div[4]/span[2]')))).text

while True:
    if self.text_1 == self.current_answer:
        (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_1)))).click()
    if self.text_2 == self.current_answer:
        (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_2)))).click()
    if self.text_3 == self.current_answer:
        (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_3)))).click()
    if self.text_4 == self.current_answer:
        (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_4)))).click()

    if bot.driver.find_elements_by_class_name("largecheckboxselected") != []:
        print("all good")
        break
    else:
        print("problemo re-running")
        if self.text_1 == self.current_answer:
            (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_1)))).click()
        if self.text_2 == self.current_answer:
            (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_2)))).click()
        if self.text_3 == self.current_answer:
            (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_3)))).click()
        if self.text_4 == self.current_answer:
            (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_4)))).click()
# selects and clicks the "Next Question!" button
nextquestion_btn = WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH,('//*[@id="nextQuestion"]'))))
nextquestion_btn.click()
bot = TriviaBot()
for i in range(1, 13):
    print("Run: "+str(i))
    bot.AutoAnswer(american_presidents, "https://www.freekigames.com/american-presidents-trivia")
bot.claimRewards()
  • 使用JavaScript单击
  • 使用WebDriverWait
  • 退出并关闭驱动程序并重新打开页面
  • 继续单击,直到复选框id有效(继续循环)
  • 刷新页面并尝试再次单击(Java和normal.click()
  • 使用时间。睡眠(时间)来等待
  • 根本不使用webdriver wait,只需设置var
我曾经有一个陈旧的元素错误,但我修复了它

注意:它大部分时间都在点击,但随机的点击是不起作用的,不是错误或者其他什么

导入:

from selenium import webdriver
from time import *
from data import *
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.common.exceptions import NoSuchElementException, StaleElementReferenceException
from winsound import *
import os
def AutoAnswer(self, answers_list, link):
    global i
    if i == 1:
        self.driver.get(link)
    # sends browser to first trivia
    # sets the variable to the current question so that the correct answer can be located through answer lists

self.current_question = (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="quizContainer"]/div[2]')))).text

#setting variables for boxes and their text values. The text can be corrolated to the button allowing the bot to click the correct answer
#/html//div[@id="quizContainer"]/div[@class="answersContainer"]/div[1]/span[@class="answerBox"]/a[@name="checkboxtag"]

for i in range(0, len(answers_list)):
    if answers_list[i]["question"] == self.current_question:
        self.current_answer = answers_list[i]["answer"]


self.xpath_1  = '//*[@id="quizContainer"]/div[3]/div[1]/span[1]/a'
self.text_1   = ((WebDriverWait(self.driver, 120)).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="quizContainer"]/div[3]/div[1]/span[2]')))).text


self.xpath_2  = '//*[@id="quizContainer"]/div[3]/div[2]/span[1]/a'
self.text_2   = ((WebDriverWait(self.driver, 120)).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="quizContainer"]/div[3]/div[2]/span[2]')))).text


self.xpath_3  = '//*[@id="quizContainer"]/div[3]/div[3]/span[1]/a'
self.text_3   = ((WebDriverWait(self.driver, 120)).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="quizContainer"]/div[3]/div[3]/span[2]')))).text


self.xpath_4  = '//*[@id="quizContainer"]/div[3]/div[4]/span[1]/a'
self.text_4   = ((WebDriverWait(self.driver, 120)).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="quizContainer"]/div[3]/div[4]/span[2]')))).text

while True:
    if self.text_1 == self.current_answer:
        (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_1)))).click()
    if self.text_2 == self.current_answer:
        (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_2)))).click()
    if self.text_3 == self.current_answer:
        (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_3)))).click()
    if self.text_4 == self.current_answer:
        (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_4)))).click()

    if bot.driver.find_elements_by_class_name("largecheckboxselected") != []:
        print("all good")
        break
    else:
        print("problemo re-running")
        if self.text_1 == self.current_answer:
            (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_1)))).click()
        if self.text_2 == self.current_answer:
            (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_2)))).click()
        if self.text_3 == self.current_answer:
            (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_3)))).click()
        if self.text_4 == self.current_answer:
            (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_4)))).click()
# selects and clicks the "Next Question!" button
nextquestion_btn = WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH,('//*[@id="nextQuestion"]'))))
nextquestion_btn.click()
bot = TriviaBot()
for i in range(1, 13):
    print("Run: "+str(i))
    bot.AutoAnswer(american_presidents, "https://www.freekigames.com/american-presidents-trivia")
bot.claimRewards()
部分代码:

from selenium import webdriver
from time import *
from data import *
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.common.exceptions import NoSuchElementException, StaleElementReferenceException
from winsound import *
import os
def AutoAnswer(self, answers_list, link):
    global i
    if i == 1:
        self.driver.get(link)
    # sends browser to first trivia
    # sets the variable to the current question so that the correct answer can be located through answer lists

self.current_question = (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="quizContainer"]/div[2]')))).text

#setting variables for boxes and their text values. The text can be corrolated to the button allowing the bot to click the correct answer
#/html//div[@id="quizContainer"]/div[@class="answersContainer"]/div[1]/span[@class="answerBox"]/a[@name="checkboxtag"]

for i in range(0, len(answers_list)):
    if answers_list[i]["question"] == self.current_question:
        self.current_answer = answers_list[i]["answer"]


self.xpath_1  = '//*[@id="quizContainer"]/div[3]/div[1]/span[1]/a'
self.text_1   = ((WebDriverWait(self.driver, 120)).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="quizContainer"]/div[3]/div[1]/span[2]')))).text


self.xpath_2  = '//*[@id="quizContainer"]/div[3]/div[2]/span[1]/a'
self.text_2   = ((WebDriverWait(self.driver, 120)).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="quizContainer"]/div[3]/div[2]/span[2]')))).text


self.xpath_3  = '//*[@id="quizContainer"]/div[3]/div[3]/span[1]/a'
self.text_3   = ((WebDriverWait(self.driver, 120)).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="quizContainer"]/div[3]/div[3]/span[2]')))).text


self.xpath_4  = '//*[@id="quizContainer"]/div[3]/div[4]/span[1]/a'
self.text_4   = ((WebDriverWait(self.driver, 120)).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="quizContainer"]/div[3]/div[4]/span[2]')))).text

while True:
    if self.text_1 == self.current_answer:
        (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_1)))).click()
    if self.text_2 == self.current_answer:
        (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_2)))).click()
    if self.text_3 == self.current_answer:
        (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_3)))).click()
    if self.text_4 == self.current_answer:
        (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_4)))).click()

    if bot.driver.find_elements_by_class_name("largecheckboxselected") != []:
        print("all good")
        break
    else:
        print("problemo re-running")
        if self.text_1 == self.current_answer:
            (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_1)))).click()
        if self.text_2 == self.current_answer:
            (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_2)))).click()
        if self.text_3 == self.current_answer:
            (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_3)))).click()
        if self.text_4 == self.current_answer:
            (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_4)))).click()
# selects and clicks the "Next Question!" button
nextquestion_btn = WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH,('//*[@id="nextQuestion"]'))))
nextquestion_btn.click()
bot = TriviaBot()
for i in range(1, 13):
    print("Run: "+str(i))
    bot.AutoAnswer(american_presidents, "https://www.freekigames.com/american-presidents-trivia")
bot.claimRewards()
运行代码:

from selenium import webdriver
from time import *
from data import *
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.common.exceptions import NoSuchElementException, StaleElementReferenceException
from winsound import *
import os
def AutoAnswer(self, answers_list, link):
    global i
    if i == 1:
        self.driver.get(link)
    # sends browser to first trivia
    # sets the variable to the current question so that the correct answer can be located through answer lists

self.current_question = (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="quizContainer"]/div[2]')))).text

#setting variables for boxes and their text values. The text can be corrolated to the button allowing the bot to click the correct answer
#/html//div[@id="quizContainer"]/div[@class="answersContainer"]/div[1]/span[@class="answerBox"]/a[@name="checkboxtag"]

for i in range(0, len(answers_list)):
    if answers_list[i]["question"] == self.current_question:
        self.current_answer = answers_list[i]["answer"]


self.xpath_1  = '//*[@id="quizContainer"]/div[3]/div[1]/span[1]/a'
self.text_1   = ((WebDriverWait(self.driver, 120)).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="quizContainer"]/div[3]/div[1]/span[2]')))).text


self.xpath_2  = '//*[@id="quizContainer"]/div[3]/div[2]/span[1]/a'
self.text_2   = ((WebDriverWait(self.driver, 120)).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="quizContainer"]/div[3]/div[2]/span[2]')))).text


self.xpath_3  = '//*[@id="quizContainer"]/div[3]/div[3]/span[1]/a'
self.text_3   = ((WebDriverWait(self.driver, 120)).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="quizContainer"]/div[3]/div[3]/span[2]')))).text


self.xpath_4  = '//*[@id="quizContainer"]/div[3]/div[4]/span[1]/a'
self.text_4   = ((WebDriverWait(self.driver, 120)).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="quizContainer"]/div[3]/div[4]/span[2]')))).text

while True:
    if self.text_1 == self.current_answer:
        (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_1)))).click()
    if self.text_2 == self.current_answer:
        (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_2)))).click()
    if self.text_3 == self.current_answer:
        (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_3)))).click()
    if self.text_4 == self.current_answer:
        (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_4)))).click()

    if bot.driver.find_elements_by_class_name("largecheckboxselected") != []:
        print("all good")
        break
    else:
        print("problemo re-running")
        if self.text_1 == self.current_answer:
            (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_1)))).click()
        if self.text_2 == self.current_answer:
            (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_2)))).click()
        if self.text_3 == self.current_answer:
            (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_3)))).click()
        if self.text_4 == self.current_answer:
            (WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH, self.xpath_4)))).click()
# selects and clicks the "Next Question!" button
nextquestion_btn = WebDriverWait(self.driver, 120).until(EC.element_to_be_clickable((By.XPATH,('//*[@id="nextQuestion"]'))))
nextquestion_btn.click()
bot = TriviaBot()
for i in range(1, 13):
    print("Run: "+str(i))
    bot.AutoAnswer(american_presidents, "https://www.freekigames.com/american-presidents-trivia")
bot.claimRewards()
数据.py

username = "username"
password = "password"
american_presidents = [
    {"question" : "Who was the 1st president of the United States?",
     "answer"   : "George Washington"},
    {"question" : "Who was the 2nd president of the United States?",
     "answer"   : "John Adams"},
    {"question" : "Who was the 3rd president of the United States?",
     "answer"   : "Thomas Jefferson"},
    {"question" : "Who was the 4th president of the United States?",
     "answer"   : "James Madison"},
    {"question" : "Who was the 5th president of the United States?",
     "answer"   : "James Monroe"},
    {"question" : "Who was the 6th president of the United States?",
     "answer"   : "John Quincy Adams"},
    {"question" : "Who was the 7th president of the United States?",
     "answer"   : "Andrew Jackson"},
    {"question" : "Who was the 8th president of the United States?",
     "answer"   : "Martin Van Buren"},
    {"question" : "Who was the 9th president of the United States?",
     "answer"   : "William Henry Harrison"},
    {"question" : "Who was the 10th president of the United States?",
     "answer"   : "John Tyler"},
    {"question" : "Who was the 11th president of the United States?",
     "answer"   : "James K. Polk"},
    {"question" : "Who was the 12th president of the United States?",
     "answer"   : "Zachary Taylor"},
    {"question" : "Who was the 13th president of the United States?",
     "answer"   : "Millard Fillmore"},
    {"question" : "Who was the 14th president of the United States?",
     "answer"   : "Franklin Pierce"},
    {"question" : "Who was the 15th president of the United States?",
     "answer"   : "James Buchanan"},
    {"question" : "Who was the 16th president of the United States?",
     "answer"   : "Abraham Lincoln"},
    {"question" : "Who was the 17th president of the United States?",
     "answer"   : "Andrew Johnson"},
    {"question" : "Who was the 18th president of the United States?",
     "answer"   : "Ulysses S. Grant"},
    {"question" : "Who was the 19th president of the United States?",
     "answer"   : "Rutherford B. Hayes"},
    {"question" : "Who was the 20th president of the United States?",
     "answer"   : "James A. Garfield"},
    {"question" : "Who was the 21st president of the United States?",
     "answer"   : "Chester A. Arthur"},
    {"question" : "Who was the 22nd president of the United States?",
     "answer"   : "Grover Cleveland"},
    {"question" : "Who was the 23rd president of the United States?",
     "answer"   : "Benjamin Harrison"},
    {"question" : "Who was the 24th president of the United States?",
     "answer"   : "Grover Cleveland"},
    {"question" : "Who was the 25th president of the United States?",
     "answer"   : "William McKinley"},
    {"question" : "Who was the 26th president of the United States?",
     "answer"   : "Theodore Roosevelt"},
    {"question" : "Who was the 27th president of the United States?",
     "answer"   : "William Howard Taft"},
    {"question" : "Who was the 28th president of the United States?",
     "answer"   : "Woodrow Wilson"},
    {"question" : "Who was the 29th president of the United States?",
     "answer"   : "Warren G. Harding"},
    {"question" : "Who was the 30th president of the United States?",
     "answer"   : "Calvin Coolidge"},
    {"question" : "Who was the 31st president of the United States?",
     "answer"   : "Herbert Hoover"},
    {"question" : "Who was the 32nd president of the United States?",
     "answer"   : "Franklin D. Roosevelt"},
    {"question" : "Who was the 33rd president of the United States?",
     "answer"   : "Harry S. Truman"},
    {"question" : "Who was the 34th president of the United States?",
     "answer"   : "Dwight D. Eisenhower"},
    {"question" : "Who was the 35th president of the United States?",
     "answer"   : "John F. Kennedy"},
    {"question" : "Who was the 36th president of the United States?",
     "answer"   : "Lyndon B. Johnson"},
    {"question" : "Who was the 37th president of the United States?",
     "answer"   : "Richard Nixon"},
    {"question" : "Who was the 38th president of the United States?",
     "answer"   : "Gerald Ford"},
    {"question" : "Who was the 39th president of the United States?",
     "answer"   : "Jimmy Carter"},
    {"question" : "Who was the 40th president of the United States?",
     "answer"   : "Ronald Reagan"},
    {"question" : "Who was the 41st president of the United States?",
     "answer"   : "George H. W. Bush"},
    {"question" : "Who was the 42nd president of the United States?",
     "answer"   : "Bill Clinton"},
    {"question" : "Who was the 43rd president of the United States?",
     "answer"   : "George W. Bush"},
    {"question" : "Who was the 44th president of the United States?",
     "answer"   : "Barack Obama"}

]

chemical_elements = [
    {"question" : "Most of the earth's atmosphere consists of this gas.",
     "answer"   : "N"},
    {"question" : "The symbol 'Au' refers to which chemical element?",
     "answer"   : "Gold"},
    {"question" : "The symbol 'Co' refers to which chemical element?",
     "answer"   : "Cobalt"},
    {"question" : "The symbol 'Cu' refers to which chemical element?",
     "answer"   : "Copper"},
    {"question" : "The symbol 'F' refers to which chemical element?",
     "answer"   : "Fluorine"},
    {"question" : "The symbol 'H' refers to which chemical element?",
     "answer"   : "Hydrogen"},
    {"question" : "The symbol 'Pb' refers to which chemical element",
     "answer"   : "Lead"},
    {"question" : "The symbol 'S' refers to which chemical element?",
     "answer"   : "Sulfur"},
    {"question" : "This element give plants the energy they need to grow.",
     "answer"   : "P"},
    {"question" : "This element is the building block of life.",
     "answer"   : "C"},
    {"question" : "This element was discovered by Hans Christian Oersted in 1825.",
     "answer"   : "Al"},
    {"question" : "This element was discovered by Joseph Priestly and Carl Scheele in 1774.",
     "answer"   : "O"},
    {"question" : "This element was discovered in 1808.",
     "answer"   : "B"},
    {"question" : "This element when combined with Chlorine makes table salt.",
     "answer"   : "Na"},
    {"question" : "What is the symbol for Potassium?",
     "answer"   : "K"},
    {"question" : "Which element has a reddish color in a gas and liquid state?",
     "answer"   : "Br"},
    {"question" : "Which element has a silver-gray appearance?",
     "answer"   : "Zn"},
    {"question" : "Which of these elements is considered a Metal.",
     "answer"   : "Fe"},
    {"question" : "Which of these elements is NOT considered a Metalloid.",
     "answer"   : "Sn"},
    {"question" : "Which of these elements is NOT considered a Noble Gas.",
     "answer"   : "H"}

]
我已经看到了以前的一些答案,它们与已解决的陈旧元素错误有关。我认为这是一个不同的问题。

还有三个想法:

  • 请稍候:

    Wait fluentWait=新fluentWait(驱动程序)
    .带超时(30,时间单位。秒)
    .pollingEvery(300,时间单位为毫秒)
    .忽略(NoSuchElementException.class)
    .忽略(StaleElementReferenceException.class);

    publicwebelement fluentWait(By){
    WebElement waitElement=null;
    试一试{
    waitElement=fluentWait.until(webDriver->getDriver().findElement(by));
    }catch(TimeoutException ex){}
    返回元素;
    }

  • 使用actions类

    WebElement=fluentWait(by);
    Actions Actions=新操作(getDriver());
    actions.moveToElement(元素);
    操作。单击();
    actions.build().perform();

  • 找出您应该等待的事件。应用程序是用Angular?React?JQuery编写的吗


  • 我非常抱歉。我专注于我的代码,而不是其他任何东西,我没有注意到它总是在“化学元素琐事”上失败。我也没有注意到它总是在一个问题上失败;这是因为我忘了在data.py字典问题中输入一个单词。现在一切都正常了

    谢谢你们的帮助。我再次道歉


    我现在觉得自己很笨://

    这可能是一个同步问题。尝试在支票之前等待。你能详细说明一下吗。什么样的等待,什么支票。我应该插入什么行,或者给你正在谈论的支票命名。谢谢你能提供复选框HTML代码吗?选中时:谢谢你的回复,但这是Java还是JavaScript?我是使用Python。如果这是Python,那么我不知道如何使用它。请告诉我您可能会发现的另一个问题,一些动态构建DOM树的网站会给您带来问题,如果您在单击之前不等待一点。例如,您想单击在执行某个操作后出现的按钮。您执行该操作,然后等待按钮显示,然后单击,但是,单击事件可能尚未绑定(您正在与网站脚本竞争),单击将被触发,但不执行任何操作,然后在下一个操作中失败。