selenium启动chrome模拟器模拟手机

一、如果chrome选项里边有这个模拟设备(比如iPhone 6 Plus):

1、先启动Selenium Grid, 比如命令:java -jar selenium-server-standalone-XXX.jar。

2、代码如下:

#coding=utf-8
from selenium import webdriver

mobile_emulation = { "deviceName": "Apple iPhone 6 Plus" }
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())

二、如果chrome选项里边没有预置这个模拟设备,也可以自己配置,代码如下:

#coding=utf-8
from selenium import webdriver

mobile_emulation = {
    "deviceMetrics": { "width": 414, "height": 736, "pixelRatio": 3.0 },
    "userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1" }
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
driver = webdriver.Chrome(chrome_options = chrome_options)
时间: 2024-08-02 01:12:10

selenium启动chrome模拟器模拟手机的相关文章

chrome浏览器模拟手机 地理定位

chrome浏览器模拟手机 地理定位 在pc端做touch页面调试的时候,常常会遇到需要模拟定位的情况 chrome浏览器有着强大的调试工具,尤其是新版chrome浏览器 下面我就以新版chrome浏览器为例,模拟下如何用电脑模拟手机定位 1.首先 F12 调出控制台 2. 点击这个小手机调出手机模拟器 3.选择一款手机 4.如图所示,选择emulation -- sensors  --- coordinates  需要手动填写纬度和经度 酱紫就可以模拟定位啦,是不是很简单,嘻嘻!~^_^

selenium启动Chrome时,加载用户配置文件

selenium启动Chrome时,加载用户配置文件 Selenium操作浏览器是不加载任何配置的,网上找了半天,关于Firefox加载配置的多点,Chrome资料很少,下面是关于加载Chrome配置的方法: 一.加载所有Chrome配置 用Chrome地址栏输入chrome://version/,查看自己的“个人资料路径”,然后在浏览器启动时,调用这个配置文件,代码如下: #coding=utf-8 from selenium import webdriver option = webdriv

selenium启动chrome出错处理:Message: 'chromedriver' executable needs to be in PATH

selenium启动chrome出错处理:Message: 'chromedriver' executable needs to be in PATH

早上在linux下用selenium启动Chrome时出现问题:

早上在linux下用selenium启动Chrome时出现问题:报错: Traceback (most recent call last): File "get2.py", line 62, in <module> browser = webdriver.Chrome() File "/root/.pyenv/versions/anaconda3-5.1.0/lib/python3.6/site-packages/selenium/webdriver/chrome

电脑手机模拟器模拟手机浏览器,在线浏览手机网站

很多手机网站都通过User-Agent来判断当前访问客的浏览器类型,如果是3G智能手机,显示手机版页面内容,如果是电脑浏览器,显示普通电脑版网页内容. 谷歌Chrome电脑浏览器,可以很方便地用来当3G手机模拟器来模拟手机浏览器.在Windows的[开始]-->[运行]中输入以下命令,启动谷歌浏览器,即可模拟相应手机浏览器去访问3G手机网页: 谷歌Android版手机模拟器: chrome.exe --user-agent="Mozilla/5.0 (Linux; U; Android 2

无需插件,直接加参数,chrome即可模拟手机浏览器

在目标那里加一段参数即可:--user-agent="mozilla/5.0 (linux; u; android 2.3.3; en-us; sdk build/ gri34) applewebkit/533.1 (khtml, like gecko) version/4.0 mobile safari/533.1" 这样就可以模拟手机浏览器访问了,方便自己调试,添加之后,必须关闭当前浏览器,然后再打开才可以

Mac下用selenium启动Chrome浏览器问题解决

之前在mac的Python shell中,无法通过driver=webdriver.Chrome()启动谷歌浏览器.现解决方法如下: (前提:Chromedriver在/usr/local/bin/目录下) from selenium import webdriver browser = webdriver.Chrome(executable_path="/usr/local/bin/chromedriver") 或: from selenium import webdriver pa

用selenium启动chrome浏览器

python 3.7 pycharm 1.安装selenium pip3 install selenium 2.下载与chrome匹配的chromdriver.exe,放到项目的解释器路径下,跟python.exe同一个路径 随笔最后附上匹配列表和下载链接 注:如果chromedriver.exe与chrome不匹配,启动会出现各种错误,比如启动不了,或者启动后不能正常访问网址 3.程序: from selenium import webdriver from time import sleep

Chrome浏览器模拟手机访问网站

1. 按F12开打开发者工具,点击红框部分按钮 2. 点击红框部分 3. 输入网址试一下