【发布时间】:2015-06-28 12:41:14
【问题描述】:
这几天我尝试使用 Selenium 框架。这个框架有两个问题。
- 在少数情况下,我会出现以下错误:“org.openqa.selenium.ElementNotVisibleException: You may only interact with visible elements”
但是我的元素是完全可见的,并且我在此页面上只有一个具有此名称的元素。当我更改浏览器版本时,可以避免这个错误,但它很烦人......
- 在少数情况下,我获得了网站的移动版本,但没有找到任何解决方案。我怎样才能避免这种情况?
这是我在 twitter 上的代码示例:
public static void main(String[] args) {
HtmlUnitDriver htmlUnit = new HtmlUnitDriver(DesiredCapabilities.firefox());
WebDriver driver = htmlUnit;
goToTwitter(driver);
}
public static void goToTwitter(WebDriver driver){
driver.get("http://www.twitter.fr/login");
// Find the text input element by its name
WebElement element = driver.findElement(By.name("session[username_or_email]"));
WebElement element2 = driver.findElement(By.name("session[password]"));
// Enter something to search for
element.sendKeys("****");
element2.sendKeys("****");
// Now submit the form. WebDriver will find the form for us from the element
element.submit();
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
System.out.println("Page title is: " + driver.getCurrentUrl());
}
GetCurrentUrl 返回“mobile.twitter.com”,我需要这个站点的桌面版本。
所以我的问题是我们如何强制网站使用此框架返回桌面版本?
【问题讨论】:
标签: java selenium mobile browser desktop