我有这段代码,但运行后我在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)
答案 0 :(得分: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)