【发布时间】:2020-04-07 03:33:24
【问题描述】:
我在 selenium webdriver 中使用动作链下拉,这是我的代码,谁能帮我找出问题所在。这次我没有使用页面对象模式,所以这里没有“self”参数。
from selenium import webdriver
from behave import given, when, then
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
@given('Open RF page')
def open_website(context):
context.driver.get('https://www.raymourflanigan.com/')
@when('Select Living Room')
def select_living_room(context):
driver = webdriver.Chrome()
actions = ActionChains(driver)
menu = context.driver.find_element(By.XPATH, "//*[@id='Container']/div[1]/div[3]/div[1]/a")
sofa = context.driver.find_element(By.XPATH, "//*[@id='Container']/div[1]/div[3]/div[1]/div/div[1]/ul/li[2]/a")
actions.move_to_element(menu).move_to_element(sofa).click()
@then("Verify {product} are available")
def verify(context, product):
result = context.driver.find_element(By.CSS_SELECTOR, "h1.Category_Bnr_Title").text
assert 'Sofas & Couches' in result, f"Expected text is: {result}."
另外,我删除了perform(),因为由于某种原因,第二个函数不能在其中使用perform()。似乎没有它也无法正常工作,所以如果有人知道为什么并且可以帮助我,那就太好了!我只是学习)提前谢谢你!
【问题讨论】:
标签: python selenium selenium-webdriver automation