Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Selenium TouchEvent在设备仿真中不起作用_Java_Selenium - Fatal编程技术网

Java Selenium TouchEvent在设备仿真中不起作用

Java Selenium TouchEvent在设备仿真中不起作用,java,selenium,Java,Selenium,需要在桌面浏览器上使用移动设备仿真来自动化测试 如果通过ChromeOptions()启用仿真,则触摸屏的仿真不起作用(按钮响应光标等)。这就是为什么我使用java.awt.Robot(F12>Ctrl+Shift+M>iPad)来打开设备仿真。但是触摸不起作用 import org.openqa.selenium.By; 导入org.openqa.selenium.WebElement; 导入org.openqa.selenium.chrome.ChromeDriver; 导入org.open

需要在桌面浏览器上使用移动设备仿真来自动化测试

如果通过ChromeOptions()启用仿真,则触摸屏的仿真不起作用(按钮响应光标等)。这就是为什么我使用java.awt.Robot(F12>Ctrl+Shift+M>iPad)来打开设备仿真。但是触摸不起作用

import org.openqa.selenium.By;
导入org.openqa.selenium.WebElement;
导入org.openqa.selenium.chrome.ChromeDriver;
导入org.openqa.selenium.interactions.touch.TouchActions;
//设置浏览器类型和平台
驱动器设置。新闻设置(“https://staging.myev.com,DriverType.CHROME,EmulationType.MOBILE);
WebDriver-driver=DriverSettings.getDriver();
驱动程序。获取(“https://google.com");
WebElement=driver.findElement(By.xpath(//a[@class='gb\u x gb\u Ub']);
TouchActions TouchActions=新的TouchActions(驱动程序);
touchActions.singleTap(元素).perform();
按钮未按下且没有错误-“进程已完成,退出代码为0”


也许还有其他方法可以启用移动仿真或使用TouchActions?

根据官方网站的规范:,要正确使用ChromeDriver的移动仿真,您应该使用:

Map<String, String> mobileEmulation = new HashMap<>();

mobileEmulation.put("deviceName", "Nexus 5");


ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);

WebDriver driver = new ChromeDriver(chromeOptions)
Map mobileEmulation=new HashMap();
mobileEmulation.put(“deviceName”、“Nexus 5”);
ChromeOptions ChromeOptions=新的ChromeOptions();
色度选项。设置实验选项(“移动模拟”,移动模拟);
WebDriver驱动程序=新的ChromeDriver(chromeOptions)
*还可以自定义模拟设备,为此,您需要使用存储的自定义设备属性声明自定义会话存储。这需要完成,因为如果您没有特别声明chrome会话存储,那么每次启动新的测试会话时,都会创建一个带有默认设置的临时会话

在这里,您可以找到启动chromedriver的有用命令列表:

根据官方网站的规范:,要正确使用ChromeDriver的移动仿真,您应该使用:

Map<String, String> mobileEmulation = new HashMap<>();

mobileEmulation.put("deviceName", "Nexus 5");


ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);

WebDriver driver = new ChromeDriver(chromeOptions)
Map mobileEmulation=new HashMap();
mobileEmulation.put(“deviceName”、“Nexus 5”);
ChromeOptions ChromeOptions=新的ChromeOptions();
色度选项。设置实验选项(“移动模拟”,移动模拟);
WebDriver驱动程序=新的ChromeDriver(chromeOptions)
*还可以自定义模拟设备,为此,您需要使用存储的自定义设备属性声明自定义会话存储。这需要完成,因为如果您没有特别声明chrome会话存储,那么每次启动新的测试会话时,都会创建一个带有默认设置的临时会话

在这里,您可以找到启动chromedriver的有用命令列表:

如何启用移动仿真?你能分享你的代码吗?我知道这可能不是最快的解决方案,但如果其他方法都失败了,Appium可能更适合。它有一套独立于Selenium的touchactions,但它并不是一个快速而肮脏的实现机器人按键(KeyEvent.VK_F12);robot.keyRelease(KeyEvent.VK_F12);暂停(500);机器人按键(KeyEvent.VK_控制);机器人按键(KeyEvent.VK_SHIFT);robot.keyPress(KeyEvent.VK_M);robot.keyRelease(KeyEvent.VK_控制);机器人。按键释放(按键事件。VK_移位);robot.keyrease(KeyEvent.VK_M)`如何启用移动仿真?你能分享你的代码吗?我知道这可能不是最快的解决方案,但如果其他方法都失败了,Appium可能更适合。它有一套独立于Selenium的touchactions,但它并不是一个快速而肮脏的实现机器人按键(KeyEvent.VK_F12);robot.keyRelease(KeyEvent.VK_F12);暂停(500);机器人按键(KeyEvent.VK_控制);机器人按键(KeyEvent.VK_SHIFT);robot.keyPress(KeyEvent.VK_M);robot.keyRelease(KeyEvent.VK_控制);机器人。按键释放(按键事件。VK_移位);robot.keyrease(KeyEvent.VK_M)`