2015-07-22 194 views
1

我在學習自動化,我有幾組登錄ID,我試圖在amazon.com網站上登錄和註銷,並使用一組登錄ID和密碼在一個excel文件中。如何使用Python中的Selenium進行參數化/數據驅動的測試

問題我正在面對的是要弄清楚如何將鼠標懸停在亞馬遜主頁的「你好」上並點擊登錄。我嘗試過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() 
+0

你有什麼試過的?數據源在哪裏?你的問題的標題似乎與「問題如何懸停在元素你好」無關 – lloyd

+0

我有2個阻滯劑在這裏我的主要問題是要弄清楚如何在amazon.com的登錄頁面上做參數化!但在進入該頁面之前,我被困在懸停場景中,點擊我在亞馬遜的主頁上的帳戶 – Ghousia

回答

1

從代碼刪除此行

mouse_over("//*[@id='nav-link-yourAccount]") 

正確的x路徑 - :

hover = driver.find_element_by_xpath("//*[@id='nav-link-yourAccount']") 

其餘部分是確定。

+0

但它沒有檢測到xpath。 – Ghousia

+0

此外,我的問題仍然沒有得到答覆。如何參數化多個登錄ID /密碼。 – Ghousia

+0

希望這個鏈接help-:http://tobyho.com/2009/03/12/parameterizing-your-tests/ – Sandeep

相關問題