2017-06-21 40 views
1

我用硒的webdriver來從一個網址的一些內容,但我發現了以下錯誤: This picture show the dropdown list, I got the url content through the real browser硒的webdriver沒有顯示下拉列表像一個真正的瀏覽器

This picture not show the dropdown list, I got the url content through the selenium webdriver

我不知道爲什麼,請幫我。非常感謝你。 這是我的代碼:

司機= webdriver.Chrome() driver.get(「myurl」)

+0

原因是因爲,硒驅動程序每次啓動帶有新配置文件的瀏覽器(此配置文件不會與任何其他帳戶(如Gmail或FB)鏈接),但在真實瀏覽器中,它會與某種帳戶鏈接因爲我們看到的廣告或類似的東西可能會有所不同。 –

+0

@santhosh kumar謝謝。有一些解決方案嗎? –

回答

0

的原因是因爲,硒司機每次推出新的配置文件瀏覽器(該配置文件犯規鏈接與您的任何其他帳戶,如Gmail或FB),但在真正的瀏覽器,它會與某種帳戶鏈接,並基於這可能我在我們看到的廣告或一些類似的東西不同。爲了克服這個問題,我們可以用我們的真實瀏覽器使用的默認配置文件啓動瀏覽器下面的代碼可能會給你一些想法。

from selenium import webdriver 
from selenium.webdriver.chrome.options import Options 

options = webdriver.ChromeOptions() 
options.add_argument("user-data-dir=C:\\Path") #Path to your chrome profile 
w = webdriver.Chrome(executable_path="C:\\Users\\chromedriver.exe", chrome_options=options) 

要找到路徑到您的Chrome個人資料數據,需要chrome://version/輸入到地址欄。例如。我的顯示爲C:\Users\pc\AppData\Local\Google\Chrome\User Data\Default,要在腳本中使用它,我必須排除\Default\,所以我們最終只能使用C:\Users\pc\AppData\Local\Google\Chrome\User Data

另外,如果你想爲硒分開配置文件:將路徑替換爲任何其他路徑,如果啓動時不存在,chrome會爲它創建新的配置文件和目錄。

希望這可以幫助你。謝謝。

+0

這是完美的!謝謝! –

相關問題