问题描述
from behave import when,then,given
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import webdriverwait
SIGN_IN_POPUP_BTN = (By.CSS_SELECTOR,'#nav-signin-tooltip .nav-action-inner')
@when('Click Sign In from popup')
def click_sign_in_popup_btn(context):
e = context.driver.wait.until(EC.element_to_be_clickable(SIGN_IN_POPUP_BTN))
e.click()
@then('Verify Sign In page opens')
def verify_sign_in_page_opens(context):
assert 'https://www.amazon.com/ap/signin' in context.driver.current_url,f'Url {context.driver.current_url} does not include https://www.amazon.com/ap/signin'
解决方法
错误信息
'WebDriver' object has no attribute 'wait'
告诉您“WebDriver”,您在下面代码中的 driver
,
e = context.driver.wait.until(...)
^
没有属性 wait
。简单地说,WebDriver.wait
或在您的情况下 driver.wait
不存在。使用等待的语法在 the python docs 中。
在这种情况下,您的代码应该是
from selenium.webdriver.support import expected_conditions as EC
def click_sign_in_popup_btn(context):
wait = WebDriverWait(driver,10)
e = wait.until(EC.element_to_be_clickable(SIGN_IN_POPUP_BTN))
e.click()
或者更简单
def click_sign_in_popup_btn(context):
WebDriverWait(driver,10).until(EC.element_to_be_clickable(SIGN_IN_POPUP_BTN)).click()