我使用此代码从浏览器边框计算页面上按钮的填充。
Dimension dm = new Dimension(1024,768);
//Setting the current window to that dimension
driver.manage().window().setSize(dm);
// Click Login button to submit login form
WebDriverWait loginButtonWebDriverWait = new WebDriverWait(driver, 4000);
WebElement loginButtonWebElement = loginButtonWebDriverWait.until(ExpectedConditions.presenceOfElementLocated(By.id("login")));
int loginButtonX = loginButtonWebElement.getLocation().getX();
int loginButtonY = loginButtonWebElement.getLocation().getY();
int loginButtonWidth = loginButtonWebElement.getRect().getWidth();
int loginButtonHeight = loginButtonWebElement.getRect().getHeight();
System.out.println("Login Button is " + loginButtonX + " pixels from left border.");
System.out.println("Login Button is " + (screenWidth - loginButtonX + loginButtonWidth) + " pixels from right border.");
System.out.println("Login Button is " + loginButtonY + " pixels from top border.");
System.out.println("Login Button is " + (screenHeight - loginButtonY + loginButtonHeight) + " pixels from bottom border.");
// We need to check that the size is not less than 10 pixels. If the space is less trow exception and fail the test.
assertThat(loginButtonX).isGreaterThan(5);
assertThat(loginButtonY).isGreaterThan(5);
问题是如何计算登录按钮绑定到屏幕右下角?
1条答案
按热度按时间vq8itlhq1#
假设
coordinate system
作为:你需要做的是
和
然后它在屏幕的右下角。
如果按钮不是严格地放在角落里,可能需要添加一些填充。