2017-04-12 77 views
0

我正嘗試自動登錄到此website無法使用硒登錄

登錄菜單位於網站的右上角。

我試圖通過CSS選擇器,Xpath,名稱和此topic的操作來查找登錄表單。

編輯1:我也嘗試將鼠標懸停在動作鏈的登錄上,然後通過元素查找。沒有找到元素,也沒有發送密鑰。

結果:

的查找CSSXpath,名稱顯示:元素不可見; 動作事件:我將鼠標懸停在登錄區域上,發送密鑰,登錄區域彈出,但沒有發送密鑰,也沒有顯示錯誤。

我對動作事件代碼:

wd.get("http://www.vatgia.com") 

action = ActionChains(wd); 

action.move_to_element(wd.find_element_by_css_selector("#header_bar > div > div.fr > a:nth-child(8)")) 
action.send_keys("loginsampling") 

action.perform(); 

P/S:三江源布賴恩的編輯!

最後更新:

馬希普爾爲我提供瞭解決方案。我應該使用xpath關於容器的登錄表單和密碼。我以前只有右鍵單擊並複製xpath元素,並沒有工作。感謝Mahipal!

+0

不客氣,Kien :) – Brian

回答

0

你可以利用登錄菜單的容器識別其字段,如下圖所示:

driver.findElement(By.xpath("//div[@id='header_bar']//a[@rel='#header_login']")).click(); 

WebDriverWait wait = new WebDriverWait(driver, 10); 

wait.until(ExpectedConditions.visibilityOf(
       driver.findElement(By.xpath("//div[@id='simple_tip']//div/input[@name='loginname']")))); 

driver.findElement(By.xpath("//div[@id='simple_tip']//div/input[@name='loginname']")).sendKeys("login_name"); 

嘗試上面的代碼,讓我知道,它是否適合你。

+0

哦,我的budha它的工作原理:D謝謝你這麼多,我需要深入挖掘這一點。 Thankyou Mahipal !!! –

0

這是由於您在嘗試查找登錄按鈕之前未打開登錄下拉菜單。您需要找到Dropdown元素,點擊它,然後找到登錄字段和按鈕並執行您的操作。

+0

我做到了,我找到了下拉的元素。在元素查找中,我點擊它並試圖找到登錄表單。在動作中,我將鼠標懸停在它上面,然後嘗試發送密鑰。 –