I want to use selenium to control chrome browser. 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. 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: when my Screen Resolution is: 1920*1080 , my Code running result looks like this:
when I change my Screen Resolution to 1366*768 , my Code running result looks like this: So,we can find that,action can't move to the map element{0.5 width, 0.9 high}. How should I do?
Few points required sometimes with Actions class:
Sometimes we can use JavaScript focus method to focus on element before doing any actions using Actions class like below code:
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();
please try it. if i am not wrong, it will solve the issue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.