[英]selenium move mouse don't work with low resolution
I want to use selenium to control chrome browser. 我想用selenium来控制chrome浏览器。 In my work, i will move in a map, but selenium will work well ,when my screen resolution is 1920*1080, and it doesn't work when my screen resolution is 1366*768.
在我的工作中,我将在地图中移动,但是当我的屏幕分辨率为1920 * 1080时,selenium将运行良好,并且当我的屏幕分辨率为1366 * 768时它不起作用。 the code is that:
代码是:
ChromeDriver driver =(ChromeDriver)webDriver;
WebElement map =driver.findElementsByClassName("ol-unselectable").get(0); // a MAP
Actions actions =new Actions(driver);
System.out.println(map.getSize());
int x =map.getSize().width;
int y =map.getSize().height;
actions.moveToElement(map,0,0).perform();
actions.moveByOffset(5,5).click().perform();
actions.moveByOffset((int)(x*0.5),0).click().perform();
actions.sendKeys(Keys.DOWN).sendKeys(Keys.DOWN).sendKeys(Keys.DOWN).perform();
actions.sendKeys(Keys.DOWN).sendKeys(Keys.DOWN).sendKeys(Keys.DOWN).perform();
actions.sendKeys(Keys.DOWN).sendKeys(Keys.DOWN).sendKeys(Keys.DOWN).perform();
actions.moveToElement(map,(int)(x*0.5),(int)(y*0.8)).click().perform();
actions.doubleClick().perform();
the code 代码
actions.moveToElement(map,(int)(x*0.5),(int)(y*0.8)).click().perform();"
doesn't work when I use a low resolution. 当我使用低分辨率时不起作用。
the MAP looks like this: MAP看起来像这样:
when my Screen Resolution is: 1920*1080 , my Code running result looks like this:
当我的屏幕分辨率为: 1920 * 1080时 ,我的代码运行结果如下所示:
when I change my Screen Resolution to 1366*768 , my Code running result looks like this: 当我将屏幕分辨率更改为1366 * 768时 ,我的代码运行结果如下所示:
So,we can find that,action can't move to the map element{0.5 width, 0.9 high}.
所以,我们可以发现,动作不能移动到地图元素{0.5宽度,0.9高}。 How should I do?
我应该怎么做?
Few points required sometimes with Actions class: 有时使用Actions类几点:
Sometimes we can use JavaScript focus method to focus on element before doing any actions using Actions class like below code: 有时我们可以使用JavaScript焦点方法在使用Actions类执行任何操作之前关注元素,如下面的代码:
JavascriptExecutor js = (JavascriptExecutor) ts.getDriver(); js.executeScript("arguments[0].focus();", we); actions.moveToElement(map,(int)(x*0.5),(int)(y*0.8)).click().build().perform();
Try this : 试试这个 :
actions builder = new Actions(driver);
builder.moveToElement(map,(int)(x*0.5),(int)(y*0.8)).click().build().perform();
Maybe that will solve your problem Sorry i can not just comment under your question ... 也许那会解决你的问题抱歉我不能只根据你的问题发表评论......
Try this, 试试这个,
actions builder = new Actions(driver);
builder.moveToElement(map,(int)(x*0.5),(int)(y*0.8)).click().build().perform(); 。builder.moveToElement(地图,(int)的(X * 0.5),(INT)(Y * 0.8))点击()建立()执行()。;
please try it.
请试一试。 if i am not wrong, it will solve the issue.
如果我没有错,它将解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.