2015-02-24 43 views
0

我想模擬移動設備的測試和自動化目的。使用Chromedriver和Selenium我發現了兩種方法可以做到這一點。我可以設置用戶代理(例如,從here):mobileEmulation和在Chrome中設置用戶代理有什麼區別?

from selenium import webdriver 

options = webdriver.ChromeOptions() 
options.add_argument('--user-agent=Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3') 

driver = webdriver.Chrome(chrome_options=options) 

或者,我可以讓移動仿真(例如,從here):

from selenium import webdriver 

mobile_emulation = { "deviceName": "Google Nexus 5" } 
chrome_options = webdriver.ChromeOptions() 
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) 

driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities = chrome_options.to_capabilities()) 

有什麼區別?

回答

0

用戶代理字符串:您實質上是在向您的瀏覽器說謊。

仿真模式:你基本上是在向自己說謊你的瀏覽器。