为了账号安全,请及时绑定邮箱和手机立即绑定

等待元素 error_handler.check_response(response)

等待元素 error_handler.check_response(response)

守着星空守着你 2022-06-07 19:14:29
我有这段代码,但运行后我在 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_urldef 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)
查看完整描述

1 回答

?
白衣非少年

TA贡献1155条经验 获得超0个赞

更新了提问者的失败代码示例,错误.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 exist

WebDriverWait(self.driver, 30).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="tab-content-2"]/div/md-content/div[9]/a/span')))


# then click it

driver.find_element_by_xpath("//*[@id="tab-content-2"]/div/md-content/div[9]/a/span").click()


# Wait for the element to exist

WebDriverWait(self.driver, 30).until(EC.element_to_be_clickable((By.ID, 'adminCreateConsultation')))


# then click it -- need to use Javascript click for this element

createConsultationButton = driver.find_element_by_id("adminCreateConsultation")

driver.execute_script("arguments[0].click();", createConsultationButton) 


查看完整回答
反对 回复 2022-06-07
  • 1 回答
  • 0 关注
  • 870 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信