51Testing软件测试论坛

标题: python selenium 模拟手机浏览器 [打印本页]

作者: lsekfe    时间: 2018-7-4 14:46
标题: python selenium 模拟手机浏览器
脚本如下:
  1. from selenium import webdriver


  2. mobile = {'deviceName': 'Apple iPhone 4'}  //设置所模拟的硬件
  3. path='C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe'
  4. options = webdriver.ChromeOptions()
  5. options.add_experimental_option('mobileEmulation',mobile)
  6. driver = webdriver.Chrome(path,chrome_options=options)
  7. driver.get('http://m.baidu.com')driver.find_element_by_css_selector('#index-kw').send_keys('test')
复制代码
[attach]116959[/attach]
注意id 是 ‘index-kw’
[attach]116960[/attach]






欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2