簡體   English   中英

我的代碼 python BDD 行為循環中的動作鏈問題

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

我正在嘗試遍歷 Raymour 和 Flanigan 家具網站主頁上的元素。 我已經把所有的項目都放在一個海量中,並想使用一個動作鏈方法來點擊它並驗證每個項目是否成功打開。 由於在網站上沒有點擊選項,我使用的是動作鏈。 但我的代碼有問題。 我認為這是最后一行

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