简体   繁体   English

我的代码 python BDD 行为循环中的动作链问题

[英]problem with action chain in my code python BDD behave loop

I am trying to loop through elements on the main page of Raymour and Flanigan furniture website.我正在尝试遍历 Raymour 和 Flanigan 家具网站主页上的元素。 I've put all the items in a massive and want to use an action chain method to click through it and verify each one opens up successfully.我已经把所有的项目都放在一个海量中,并想使用一个动作链方法来点击它并验证每个项目是否成功打开。 Since on the website, there is no click option, I am using an action chain.由于在网站上没有点击选项,我使用的是动作链。 but something is wrong with my code.但我的代码有问题。 I think it's the last line我认为这是最后一行

from selenium import webdriver
from behave import given, when, then
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains

TOP_LINKS = (By.CSS_SELECTOR, "div.Hdr_MN")


@given('Main Page MyRF')
def open_website(context):
    context.driver.get('https://www.raymourflanigan.com/')


@then('User can go through top links and verify page has opened')
def click_thru_top(context):
    expected_items = ['Living Rooms', 'Dining Rooms', 'Bedrooms', 'Mattresses', 'Kids', 'Office', 'Decor', 'Rugs', 'Outlet', 'Sale']
    top_links = context.driver.find_elements(*TOP_LINKS)
    # first_item = (By.CSS_SELECTOR, "a.Hdr_MNCatLink")
    for x in range(len(top_links)):
        actions = ActionChains(context.driver)
        actions.move_to_element(top_links[x]).perform()
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.ui import WebDriverWait

driver = webdriver.Chrome()
driver.get("https://www.raymourflanigan.com/")

WebDriverWait(driver, 10).until(
    ec.visibility_of_all_elements_located((By.XPATH, "//a[@ng-if='category.URL'][text()='Kids']")))
Top_Links = driver.find_elements_by_xpath("//a[@class='Hdr_MNCatLink ng-binding ng-scope']")
for x in range(0, len(Top_Links)):
    WebDriverWait(driver, 10).until(
        ec.visibility_of_all_elements_located((By.XPATH, "//a[@ng-if='category.URL'][text()='Kids']")))
    Top_Links = driver.find_elements_by_xpath("//a[@class='Hdr_MNCatLink ng-binding ng-scope']")
    Top_Links[x].click()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM