我正在学习自动化,我有几组登录 ID,我正在尝试使用 Excel 文件中的一组登录 ID 和密码登录和注销 amazon.com 网站。
我面临的问题是弄清楚如何将鼠标悬停在亚马逊主页中的“hello”上并单击登录。我尝试过 mouse_hover(),使用 XPath 单击。然而我想要做的是,在进入登录页面后,我想使用不同的登录 ID 登录并再次注销,并使用不同的登录 ID/密码执行相同的操作。
这是我正在尝试执行的代码。
import unittest
from selenium import webdriver
from selenium.webdriver.support.ui import Select
# create a new Firefox session
driver = webdriver.Firefox()
driver.implicitly_wait(30)
driver.maximize_window()
# navigate to the application home page
driver.get("http://www.amazon.com/")
if 'Sign Out' in driver.page_source:
pass
else:
mouse_over("//*[@id='nav-link-yourAccount]")
hover = driver.find_element_by_xpath("//*[@id='nav-link-yourAccount]")
hover.click()
logi = driver.find_element_by_xpath("//*[@id='nav-flyout-ya-signin']")
logi.click()
# username = driver.find_element_by_id("login_login_username")
# username.send_keys("student2")
# password= driver.find_element_by_id("login_login_password")
# password.send_keys("Testing1")
# loginbutton=driver.find_element_by_id("login_submit")
# loginbutton.click()
最佳答案
从代码中删除此行
mouse_over("//*[@id='nav-link-yourAccount]")
正确的 x 路径-:
hover = driver.find_element_by_xpath("//*[@id='nav-link-yourAccount']")
其余部分没问题。
关于python - 如何在 Python 中使用 Selenium 进行参数化/数据驱动测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31553620/