2016-08-24 29 views
-1
  1. 訪問google.com
  2. 鍵入搜索關鍵字
  3. 我想選擇從自動建議列表第三/第四值選擇從自動建議值。我應該在硒蟒蛇中使用什麼方法?
+0

這裏有三個獨立的問題:「我如何導航到一個靜態的URI」 「如何選擇文本框並在字段中輸入?」 和「如何點擊選項?」 – Izzy

回答

0

谷歌搜索頁面包含<div class="gstl_0 sbdd_a">

當你開始輸入到搜索框中,該分區變得與<ul role="listbox">填充。該列表中的<li>包含4條建議。選擇一個,然後調用.click()方法。

1

我不知道蟒蛇,但我確實有C#代碼,我可以成功。你可以試試看。

IWebDriver driver = new InternetExplorerDriver(); 
driver.Navigate().GoToUrl("https://www.google.com/"); 

IWebElement txtboxSearch = driver.FindElement(By.Id("lst-ib")); 
txtboxSearch.SendKeys("ap"); 

IList<IWebElement> autosaerchList = driver.FindElements(By.CssSelector(".sbsb_c.gsfs")); 
autosaerchList[1].Click(); 
0
from selenium import webdriver 
import time 


driver = webdriver.Chrome('Path to chromedriver\chromedriver.exe') 

driver.get('http://google.com') 
driver.maximize_window() 
driver.find_element_by_name('q').send_keys('Shah') #pass whatever you want to search 
time.sleep(5) 

# to click on third element of search suggestion 
driver.find_element_by_xpath('//div/div[3]/form/div[2]/div[2]/div[1]/div[2]/div[2]/div[1]/div/ul/li[3]/div/div[2]').click() 

# to click on fourth element of search suggestion, uncomment the next line and comment the previous one 
#driver.find_element_by_xpath('//div/div[3]/form/div[2]/div[2]/div[1]/div[2]/div[2]/div[1]/div/ul/li[4]/div/div[2]').click() 

希望這有助於

相關問題