1

I am in the process of creating script using WebDriver for filter functionality for an application which has field names , operands and search value text boxes.

I have the script for selecting the values from operands drop down like below

List <WebElement> filterdrp = (List<WebElement>) driver.findElements(By.xpath("html/body/div[6]/div/div[2]/div[2]/div/div[2]/div[1]/div/div[2]/div/div[2]"));
WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div[6]/div/div[2]/div[2]/div/div[2]/div[1]/div/div[2]/div/div[2]/div[21]")));
int size = filterdrp.size();
System.out.println(size);
for(int i=1;i<=size;i++)
        {
            Actions actions = new Actions(driver);
            actions.sendKeys(Keys.DOWN).build().perform();//press down arrow key
            actions.sendKeys(Keys.ENTER).build().perform();//press enter
        }

When I run the script without the above lines, the script is able to identify the search value text box and it runs. When I use these lines I get the error message as

org.openqa.selenium.ElementNotVisibleException: Element is not displayed (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 159 milliseconds
Build info: version: '2.50.1', revision: 'd7fc91b', time: '2016-01-29 19:04:49'
System info: host: 'MXL4080HTD', ip: '172.18.32.188', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_101'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{browserAttachTimeout=0, ie.enableFullPageScreenshot=true, enablePersistentHover=true, ie.forceCreateProcessApi=false, ie.forceShellWindowsApi=false, pageLoadStrategy=normal, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:43373/, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss}]
Session ID: 84c8353c-3106-44fe-b0a7-6a6782c1945d
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:327)
    at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:122)
    at toStartWith.ReadIntGlobal_data.IntellaGBL_Filter(ReadIntGlobal_data.java:123)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at org.testng.TestRunner.privateRun(TestRunner.java:774)
    at org.testng.TestRunner.run(TestRunner.java:624)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
    at org.testng.SuiteRunner.run(SuiteRunner.java:261)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
    at org.testng.TestNG.run(TestNG.java:1048)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:152)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:57)

The above error is displayed when the control goes to identify the text box for search.

I am getting error at the next line which is below.

driver.findElement(By.xpath("(//input[@type='text'])[5]")).clear();     
driver.findElement(By.xpath("(//input[@type='text'])[5]")).sendKeys(values);
driver.findElement(By.className("ApplyFilter")).click();

I tried webdriver wait and other couple of options but it still throws the error.Please help. I have tried using id, name, css to find the element, It works only with xpath. Couldn't generate Relative xpath as it looks like it doesn't have one.

3
  • Not clear which lines you're erroring at. You should clarify in the question. Also why using Actions when Drop down can be handled via Select class Oct 12, 2016 at 20:37
  • Thank you for pointing out. I have edited the question. Select class is failing as it is built using div tags. So had to use Action based on the answers that I saw from issues reported related to div tags.
    – Jai
    Oct 12, 2016 at 21:18
  • The code that you've mentioned to be erroring out does not seems to be appearing in the code block that you've mentioned. Oct 15, 2016 at 9:09

1 Answer 1

1

Not clear actually where you are getting error. Still based on my understanding logically code you have written is fine. It should not through error. Can you try below solutions:

  1. You are using "Absolute xpath" for finding element. Please cross check those as they are correct and proper for element you wanted to interact

  2. Can you use "Relative xpath". Just a try if it works

  3. I have faced few difficulties while using xpath using selenium. Can you try to find element by id or name or css or class with index

  4. May be you can find any of the parent class of element first and then check under that class or nesting might help to find child element

  5. Best solution would be check the visibility of an element before taking an action

3
  • Hi Narendra, I actually typed my response but did not get published somehow.
    – Jai
    Oct 18, 2016 at 15:13
  • You are using "Absolute xpath" for finding element. Please cross check those as they are correct and proper for element you wanted to interact Can you use "Relative xpath". Just a try if it works I have faced few difficulties while using xpath using selenium. Can you try to find element by id or name or css or class with index May be you can find any of the parent class of element first and then check under that class or nesting might help to find child element Best solution would be check the visibility of an element before taking an action
    – Jai
    Oct 18, 2016 at 15:14
  • Brother - Same thoughts I have suggested you in my answer. Does it resolve you issue is the Q :) Oct 19, 2016 at 4:09

Your Answer

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

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