答案 0 :(得分:1)
我不懂python,但我确实拥有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();
答案 1 :(得分:0)
Google搜索页面包含<div class="gstl_0 sbdd_a">
当您开始在搜索框中输入内容时,该div将填充<ul role="listbox">
。该列表中的<li>
包含4个建议。选择一个,然后调用.click()方法。
答案 2 :(得分: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()
希望这个帮助