编程语言
首页 > 编程语言> > python selenium 模拟手机浏览器

python selenium 模拟手机浏览器

作者:互联网

 

脚本如下:

 

from selenium import webdriver


mobile = {'deviceName': 'Apple iPhone 4'}  //设置所模拟的硬件
path='C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe'
options = webdriver.ChromeOptions()  
options.add_experimental_option('mobileEmulation',mobile)
driver = webdriver.Chrome(path,chrome_options=options)
driver.get('http://m.baidu.com')driver.find_element_by_css_selector('#index-kw').send_keys('test')

  注意id 是 ‘index-kw’

 

执行结果:

 

标签:webdriver,模拟手机,index,python,selenium,driver,Chrome,options
来源: https://blog.51cto.com/u_11959730/2778085