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'
问问题
1467 次
1 回答
0
错误信息
'WebDriver' object has no attribute 'wait'
driver
在下面的代码中告诉您“WebDriver” ,
e = context.driver.wait.until(...)
^
没有属性wait
。简单地说WebDriver.wait
, 或在你的情况下driver.wait
,不存在。使用等待的语法在python 文档中。
在这种情况下,您的代码应该是
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()
于 2021-02-22T05:52:33.740 回答