测一些手机网页的自动化非常好用。
- 下面是java执行代码。使用谷歌模拟手机,进行浏览网页。运行时注意
chromedriver.exe
的安装路径。
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.util.HashMap;
public class temp {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", ".\\drivers\\chromedriver.exe");
String URL = "https://www.baidu.com";
HashMap<String,String> mobileEmulation = new HashMap<String,String>();
mobileEmulation.put("deviceName","iPhone X");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("mobileEmulation", mobileEmulation);
WebDriver driver = new ChromeDriver(options);
driver.get(URL); //进入目的链接
}
}
- python执行代码
from selenium import webdriver
mobileEmulation = {'deviceName': 'Apple iPhone 4'}
options = webdriver.ChromeOptions()
options.add_experimental_option('mobileEmulation', mobileEmulation)
driver = webdriver.Chrome(executable_path='chromedriver.exe', chrome_options=options)
driver.get('http://m.baidu.com')
- RobotFrameWork执行方式参考https://blog.csdn.net/qq_45731111/article/details/104697893