4

I have been stuck in an issue while running selenium webdriver script in android device -Portrait mode. Script is running successfully in landscape mode but when we run the same script in android device keeping device in portrait mode script is failing for few actions like clicking the link, even though object locator remains same.

Script is like below:

@Test
public void testUntitled() throws Exception {
    driver.get("application uRl");
    driver.findElement(By.xpath("//ul[2]/li[2]/a/div")).click();

 //below line throws exception
    driver.findElement(By.cssSelector("<css selector>")).click();
}

Note: First two statements execute successfully in portrait mode. However the third statement driver.findElement(By.cssSelector("<css selector>")).click(); fails (in portrait mode) and throws the below exception:

org.openqa.selenium.ElementNotVisibleException: This WebElement is not visisble and may not be clicked.
Build info: version: &apos;unknown&apos;, revision: &apos;unknown&apos;, time: &apos;unknown&apos;
System info: os.name: &apos;Linux&apos;, os.arch: &apos;armv7l&apos;, os.version: &apos;2.6.36.3&apos;, java.version: &apos;0&apos;
Driver info: driver.version: unknown
Command duration or timeout: 322 milliseconds
Build info: version: &apos;2.32.0&apos;, revision: &apos;6c40c18&apos;, time: &apos;2013-04-09 17:22:56&apos;
System info: os.name: &apos;Windows 7&apos;, os.arch: &apos;x86&apos;, os.version: &apos;6.1&apos;, java.version: &apos;1.7.0_40&apos;
Session ID: 1385108177533
Driver info: org.openqa.selenium.android.AndroidDriver
Capabilities [{platform=ANDROID, acceptSslCerts=true, javascriptEnabled=true, handlesAlerts=true, browserName=android, browserConnectionEnabled=true, webStorageEnabled=true, rotatable=true, locationContextEnabled=true, applicationCacheEnabled=true, webdriver.remote.sessionid=1385108177533, takesScreenshot=true, version=13}]

Please suggest how this issue can be resolved. Is there any settings to be done for running script in portrait mode?

4
  • Does driver.findElement(By.xpath("//ul[2]/li[2]/a/div")).click(); bring up new element <css selector> without loading the page?
    – Tarun
    Commented Nov 26, 2013 at 8:34
  • No... On performing this action driver.findElement(By.xpath("//ul[2]/li[2]/a/div")).click(); , new page loads. In the newly loaded page need to click header link. Same action is passing in landscape mode but failing in portrait mode.
    – Rashmi
    Commented Nov 27, 2013 at 2:53
  • looking at the error This WebElement is not visisble and may not be clicked. are you able to click on element manually in portrait mode?
    – Tarun
    Commented Nov 27, 2013 at 3:01
  • Yes , manually I am able to click and the link is visible. For running tests in Portrait mode, Is there any settings need to be done?
    – Rashmi
    Commented Nov 28, 2013 at 3:26

1 Answer 1

1

Try to scroll to an element first, and then click.

Here are few solutions for scrolling to element:

2
  • 1
    You need to provide more information than simply linking to other sites for your responses to be helpful, particularly when you are answering questions as old as this one.
    – Kate Paulk
    Commented Jun 5, 2014 at 10:13
  • @Dmitry Cheremushkin the second link when clicked on says "page not found"
    – ilm
    Commented Dec 11, 2015 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.