等待元素 error_handler.check_response(response)

我有这段代码,但运行后我在 WebDriverWait 出现错误:


../../../../../../../venv/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py:80: in click

    self._execute(Command.CLICK_ELEMENT)

../../../../../../../venv/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py:633: in _execute

    return self._parent.execute(command, params)

../../../../../../../venv/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py:321: in execute

    self.error_handler.check_response(response)




class Consultations(unittest.TestCase):


    def setUp(self):


    opt = Options()

    opt.add_argument("--disable-infobars")

    opt.add_argument("--start-maximized")

    opt.add_argument("--kiosk")

    opt.add_argument("--disable-extensions")

    # Pass the argument 1 to allow and 2 to block

    opt.add_experimental_option("prefs", {

        "profile.default_content_setting_values.media_stream_camera": 1,

        "profile.default_content_setting_values.geolocation": 1,

        "profile.default_content_setting_values.notifications": 1

    })


    self.driver = webdriver.Chrome(chrome_options=opt)

    self.base_url = test_qa_url




def test_consultation_CCI_WBA_001(self):

    loginPage = LoginPage.Loginpage(self.driver)

    consultationPage = ConsultationsPage.Consultationspage(self.driver)

    homePage = HomePage.Homepage(self.driver)

    self.driver.get("https://test-maville.bciti.info/")


    # Login ass admin

    loginPage.check_login_page_loaded()

    loginPage.enter_username()

    loginPage.enter_password()

    loginPage.click_login()

    time.sleep(5)


    # Click on admin tab

    homePage.click_admin_tab()

    time.sleep(12)


    # Click on Consultation

    homePage.click_admin_consultations()

    time.sleep(30)


    # Click on Add consultation button

    element = WebDriverWait(self.driver, 10).until(

        EC.element_to_be_clickable((By.XPATH, admin_consultations_add_consultations_button)))


    element.click()

    time.sleep(8)


守着星空守着你
浏览 871回答 1
1回答

白衣非少年

更新了提问者的失败代码示例,错误.click():element = WebDriverWait(self.driver, 30).until( EC.element_to_be_clickable((By.XPATH, '//*[@id="tab-content-2"]/div/md-content/div[9]/a/span'))).click()element = WebDriverWait(self.driver, 30).until( EC.element_to_be_clickable((By.ID, 'adminCreateConsultation'))).click()我认为这里的问题与连接wait.until和.click()操作有关。尝试像这样拆分代码:# Wait for the element to existWebDriverWait(self.driver, 30).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="tab-content-2"]/div/md-content/div[9]/a/span')))# then click itdriver.find_element_by_xpath("//*[@id="tab-content-2"]/div/md-content/div[9]/a/span").click()# Wait for the element to existWebDriverWait(self.driver, 30).until(EC.element_to_be_clickable((By.ID, 'adminCreateConsultation')))# then click it -- need to use Javascript click for this elementcreateConsultationButton = driver.find_element_by_id("adminCreateConsultation")driver.execute_script("arguments[0].click();", createConsultationButton) 
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python