![](/img/trans.png)
[英]Python Selenium Testing. How can I extract the Auto Suggestions from search box on Google Home Page?
[英]why it is required to open google home page from chrome browser to enter search from selenium
我對我的代碼有疑問。 為什么需要打開Google網頁來搜索硒中的某些東西。為什么我們不能直接從Chrome瀏覽器中搜索。 下面是我的代碼
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
chrome_options=webdriver.ChromeOptions()
chrome_options.add_argument("--disable-infobars")
browser=webdriver.Chrome('C:/Users/chromedriver.exe',chrome_options=chrome_options)
page=browser.get('http://www.google.com')
search=browser.find_element_by_name('q')
search.send_keys('aditya')
search.send_keys(Keys.RETURN)
time.sleep(5)
為什么需要行page = browser.get(' http://www.google.com ')。 無論如何,我正在使用瀏覽器發送密鑰,為什么需要頁面?
首次實例化新的瀏覽器驅動程序時,它只是一個空白瀏覽器。 您需要導航到URL,然后才能與該頁面上的任何對象進行交互。 對於您而言,您正在嘗試執行Google搜索,因此必須先導航到該頁面,然后才能找到搜索元素。
您不必將其分配給page變量。 您應該能夠編寫:
browser.get('http://www.google.com')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.