Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

  • Web driver -Element getting query - scLocator

    Hi
    We are using smart gwt 5.1p and have an application based on that. We are in the process of introducing automation testing using selenium 2.5.3 as mentioned in (AutomatedTesting.html and UsingSelenium.html) . We are able to record the test case using selenium IDE but our main focus is using the web driver. By using scLocator and chrome driver implementation class from isomorphic I am trying to get the element but it is throwing element not found exception. Please note that all ID's are created automatically we didn't mention any ID while creating the screen. Can I able to get the element in this scenorio?

    Trying to use the below code to get element. Please find the html for the page in the screenshot

    By titleInput = ByScLocator.scLocator("//DynamicForm[ID="isc_I"]/item[name=username]/element");
    SmartClientWebDriver chromeDrv = new SmartClientChromeDriver();
    chromeDrv.type(titleInput, "Aa000000*");

    output
    org.openqa.selenium.NoSuchElementException: //DynamicForm[ID='isc_I']/item[name=username]/element
    For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html


    Can we able to get the element like this using web driver? Or do we need to record it in selenium ide and call the SeleneseRunner class to execute it always.
    Attached Files

  • #2
    How did you arrive at the locator you included above? Was it generated for you in Selenium IDE or did you compose it by hand?

    What would be more useful to us than a screenshot of the HTML would be if you could modify one of the samples in our online showcase to match your situation, and then provide locators referring to that - if there's still an issue in that case.

    Comment


    • #3
      Hi Thank you for the reply. I am able to point to the showcase and recorded the action in selenium IDE and took the generated code and tried in the code which is working fine and the code is displayed below.

      Code in selenium IDE for the smart gwt showcase sample and working fine
      =========================================
      titleInput = ByScLocator.scLocator("scLocator=//testRoot[]/member[Class=DynamicForm||index=0||length=2||classIndex=0||classLength=1]/item[name=intField||title=Integer||index=0||Class=TextItem]/element");
      drv.click(titleInput);

      Code in Selenium IDE for my application and having problem in the java application code
      ================================================================
      drv.click(ByScLocator.id("scLocator=//autoID[Class=Window||index=2||length=3||classIndex=0||classLength=1||roleIndex=0||roleLength=1||title=Login||scRole=dialog]/item[0][Class="VLayout"]/member[Class=DynamicForm||index=1||length=2||classIndex=0||classLength=1]/item[name=username||title=User%20Name||index=1||Class=TextItem]/element"));

      drv.type(ByScLocator.id("scLocator=//autoID[Class=Window||index=2||length=3||classIndex=0||classLength=1||roleIndex=0||roleLength=1||title=Login||scRole=dialog]/item[0][Class="VLayout"]/member[Class=DynamicForm||index=1||length=2||classIndex=0||classLength=1]/item[name=username||title=User%20Name||value=admin||index=1||Class=TextItem]/element"));

      Could you please check it. Please note that I removed certain fields like title from it and tried still it can't identify the element. What could be the possible reason

      Comment


      • #4
        Are you saying that the locators (on the bottom) fail in Selenium IDE as well, or only in your WebDriver Java code? If they're failing in Selenium IDE, you need to provide us the full debug-level logs for your script from the Selenium IDE console. Please also provide us the full script - either from Selenium IDE (if it's failing there) or your WebDriver Java code. Showing us just one line is making it more difficult than needed.

        It's going to be difficult for us to help if you can't provide us with a reproducible case, such a modified Showcase sample which has the problem when targeted with Selenium IDE (or WebDriver).

        Comment


        • #5
          Sorry for using different id . I have an issue with my id.The Locators is working fine in Selenium IDE for both cases (My application and smart GWT showcase) . I copied the scLocator stirng from Selenium IDE from the recording of smartgwt showcase and used that in the following java class and its worked. Then I recorded my application in selenium IDE and took the scLocator string and applied in the following java code it throws element not found exception.
          SmartGWT ShowCase Code == Working
          --------------------------------------------------

          import static org.junit.Assert.fail;

          import java.util.concurrent.TimeUnit;

          import org.junit.After;
          import org.junit.Before;
          import org.junit.Test;
          import org.openqa.selenium.By;

          import com.isomorphic.webdriver.ByScLocator;
          import com.isomorphic.webdriver.SeleneseRunner;
          import com.isomorphic.webdriver.SmartClientChromeDriver;
          import com.isomorphic.webdriver.SmartClientWebDriver;

          public class FirstTestWebRC extends SeleneseRunner {

          SmartClientWebDriver firedrv;
          private String baseUrl;
          private StringBuffer verificationErrors = new StringBuffer();

          @Before
          public void setUp() throws Exception {
          System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver_win32\\chromedriver.exe");
          firedrv = new SmartClientChromeDriver();
          baseUrl = "https://www.smartclient.com/smartgwt/showcase/?sc_selenium=true#form_validation_type";
          firedrv.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
          }

          @After
          public void tearDown() throws Exception {
          // driver.quit();
          String verificationErrorString = verificationErrors.toString();
          if (!"".equals(verificationErrorString)) {
          fail(verificationErrorString);
          }
          }

          @Test
          public void testFirstTestWeb() throws Exception {
          try{
          firedrv.get(baseUrl, true);
          By titleInput = ByScLocator.scLocator("scLocator=//testRoot[]/member[Class=DynamicForm||index=0||length=2||classIndex=0||classLength=1]/item[name=intField||title=Integer||index=0||Class=TextItem]/element");
          firedrv.click(titleInput);
          titleInput = ByScLocator.scLocator("scLocator=//testRoot[]/member[Class=DynamicForm||index=0||length=2||classIndex=0||classLength=1]/item[name=intField||title=Integer||value=abcd||index=0||Class=TextItem]/element");
          firedrv.type(titleInput, "Aa000000*");
          System.out.println("6:");
          }
          catch(Exception e)
          {
          e.printStackTrace();
          }
          }
          }

          MyApp - Problematic
          ===============

          import static org.junit.Assert.fail;

          import java.util.concurrent.TimeUnit;

          import org.junit.After;
          import org.junit.Before;
          import org.junit.Test;
          import org.openqa.selenium.By;

          import com.isomorphic.webdriver.ByScLocator;
          import com.isomorphic.webdriver.SeleneseRunner;
          import com.isomorphic.webdriver.SmartClientChromeDriver;
          import com.isomorphic.webdriver.SmartClientWebDriver;

          public class FirstTestWebRC extends SeleneseRunner {

          SmartClientWebDriver firedrv;
          private String baseUrl;
          private StringBuffer verificationErrors = new StringBuffer();

          @Before
          public void setUp() throws Exception {
          System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver_win32\\chromedriver.exe");
          firedrv = new SmartClientChromeDriver();
          baseUrl = "http://localhost:8080/index.html";
          firedrv.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
          }

          @After
          public void tearDown() throws Exception {
          // driver.quit();
          String verificationErrorString = verificationErrors.toString();
          if (!"".equals(verificationErrorString)) {
          fail(verificationErrorString);
          }
          }

          @Test
          public void testFirstTestWeb() throws Exception {
          try{
          firedrv.get(baseUrl, true);
          By titleInput = ByScLocator.scLocator("scLocator=//autoID[Class=Window||index=2||length=3||classIndex=0||classLength=1||roleIndex=0||roleLength=1||title=Login||scRole=dialog]/item[0][Class="VLayout"]/member[Class=DynamicForm||index=1||length=2||classIndex=0||classLength=1]/item[name=username||title=User%20Name||index=1||Class=TextItem]/element");
          firedrv.click(titleInput);
          titleInput = ByScLocator.scLocator("scLocator=//autoID[Class=Window||index=2||length=3||classIndex=0||classLength=1||roleIndex=0||roleLength=1||title=Login||scRole=dialog]/item[0][Class="VLayout"]/member[Class=DynamicForm||index=1||length=2||classIndex=0||classLength=1]/item[name=username||title=User%20Name||value=admin||index=1||Class=TextItem]/element");
          firedrv.type(titleInput, "Aa000000*");
          }
          catch(Exception e)
          {
          e.printStackTrace();
          }
          }
          }

          Comment


          • #6
            You said the Selenese script that was generated by interacting with your application works. Can you provide it? You should observe that in the generated Selenese script, most generated commands are preceeded by a call to waitForElementClickable() against the same locator as the command itself. When writing WebDriver code, you need to call this yourself to ensure the page is ready for the action you want to execute.

            With regard to your Java code, please note that SeleneseRunner is a tool for automatically executing existing Selenese scripts using WebDriver, and isn't needed if you're manually writing WebDriver code. You shouldn't be extending it in your situation.

            Comment


            • #7
              Hi Please find the attached selenese script. As you mentioned I tried by giving the exact list of commands in the code and the element not found exception is coming on the line where I used method "click". Please note that the method "waitForElementClickable" is not throwing the exception. I rewrite the test case like the below (Just followed the selenese scripts steps and wrote programatic way). I removed the SeleneseRunner reference.

              @Test
              public void testFirstTestWeb() throws Exception {
              try{
              firedrv.get(baseUrl, true);
              By titleInput = ByScLocator.scLocator("scLocator=//autoID[Class=Window||index=2||length=3||classIndex=0||classLength=1||roleIndex=0||roleLength=1||title=Login||scRole=dialog]/item[0][Class="VLayout"]/member[Class=DynamicForm||index=1||length=2||classIndex=0||classLength=1]/item[name=username||title=User%20Name||index=1||Class=TextItem]/element");
              firedrv.waitForElementClickable(titleInput);
              titleInput = ByScLocator.scLocator("scLocator=//autoID[Class=Window||index=2||length=3||classIndex=0||classLength=1||roleIndex=0||roleLength=1||title=Login||scRole=dialog]/item[0][Class="VLayout"]/member[Class=DynamicForm||index=1||length=2||classIndex=0||classLength=1]/item[name=username||title=User%20Name||index=1||Class=TextItem]/element");
              firedrv.click(titleInput);-----> Exception happens here
              titleInput = ByScLocator.scLocator("scLocator=//autoID[Class=Window||index=2||length=3||classIndex=0||classLength=1||roleIndex=0||roleLength=1||title=Login||scRole=dialog]/item[0][Class="VLayout"]/member[Class=DynamicForm||index=1||length=2||classIndex=0||classLength=1]/item[name=username||title=User%20Name||value=admin||index=1||Class=TextItem]/element");
              firedrv.waitForElementReadyForKeyPresses(titleInput);
              titleInput = ByScLocator.scLocator("scLocator=//autoID[Class=Window||index=2||length=3||classIndex=0||classLength=1||roleIndex=0||roleLength=1||title=Login||scRole=dialog]/item[0][Class="VLayout"]/member[Class=DynamicForm||index=1||length=2||classIndex=0||classLength=1]/item[name=username||title=User%20Name||value=admin||index=1||Class=TextItem]/element");
              firedrv.sendKeys(titleInput);

              //NO BLUR METHOD IN SELECTED DRIVER CLASS
              // titleInput =
              //ByScLocator.scLocator("scLocator=//autoID[Class=Window||index=2||length=3||classIndex=0||classLength=1||roleIndex=0||roleLength=1||title=Login||scRole=dialog]/item[0]
              //[Class="VLayout"]/member[Class=DynamicForm||index=1||length=2||classIndex=0||classLength=1]/item[name=username||title=User%20Name||value=admin||index=1||Class=TextItem]/
              //element");
              // firedrv.blur(titleInput);

              titleInput = ByScLocator.scLocator("scLocator=//autoID[Class=Window||index=2||length=3||classIndex=0||classLength=1||roleIndex=0||roleLength=1||title=Login||scRole=dialog]/item[0][Class="VLayout"]/member[Class=DynamicForm||index=1||length=2||classIndex=0||classLength=1]/item[name=username||title=User%20Name||value=admin||index=1||Class=TextItem]/element");
              firedrv.waitForElementClickable(titleInput);

              //NO FOCUS METHOD IN SELECTED DRIVER CLASS
              // titleInput =
              // ByScLocator.scLocator("scLocator=//autoID[Class=Window||index=2||length=3||classIndex=0||classLength=1||roleIndex=0||roleLength=1||title=Login||scRole=dialog]/item[0]
              //[Class="VLayout"]/member[Class=DynamicForm||index=1||length=2||classIndex=0||classLength=1]/item[name=username||title=User%20Name||value=admin||index=1||Class=TextItem]/
              //element");
              // firedrv.focus(titleInput);

              titleInput = ByScLocator.scLocator("scLocator=//autoID[Class=Window||index=2||length=3||classIndex=0||classLength=1||roleIndex=0||roleLength=1||title=Login||scRole=dialog]/item[0][Class="VLayout"]/member[Class=DynamicForm||index=1||length=2||classIndex=0||classLength=1]/item[name=username||title=User%20Name||value=admin||index=1||Class=TextItem]/element");
              firedrv.waitForElementClickable(titleInput);

              titleInput = ByScLocator.scLocator("scLocator=//autoID[Class=Window||index=2||length=3||classIndex=0||classLength=1||roleIndex=0||roleLength=1||title=Login||scRole=dialog]/item[0][Class="VLayout"]/member[Class=DynamicForm||index=1||length=2||classIndex=0||classLength=1]/item[name=username||title=User%20Name||value=admin||index=1||Class=TextItem]/element");
              firedrv.type(titleInput);
              }
              catch(Exception e)
              {
              e.printStackTrace();
              }

              }

              Exception
              ========
              org.openqa.selenium.NoSuchElementException: scLocator=//autoID[Class=Window||index=2||length=3||classIndex=0||classLength=1||roleIndex=0||roleLength=1||title=Login||scRole=dialog]/item[0][Class='VLayout']/member[Class=DynamicForm||index=1||length=2||classIndex=0||classLength=1]/item[name=username||title=User%20Name||index=1||Class=TextItem]/element
              For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html

              Driver info: driver.version: SmartClientWebDriver
              at com.isomorphic.webdriver.ByScLocator.findElement(ByScLocator.java:101)
              at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355)
              at com.isomorphic.webdriver.SmartClientWebDriver.findElement(SmartClientWebDriver.java:1335)
              at com.isomorphic.webdriver.SmartClientWebDriver.internalClick(SmartClientWebDriver.java:835)
              at com.isomorphic.webdriver.SmartClientWebDriver.click(SmartClientWebDriver.java:894)
              at FirstTestWebRC.testFirstTestWeb(FirstTestWebRC.java:46)
              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)
              Attached Files
              Last edited by Navas; 13th Mar 2018, 07:36.

              Comment


              • #8
                Not sure why you're redefining titleInput at the top when it's the same locator. What's the return value of firedrv.waitForElementClickable(titleInput)? If it's false, it means the operation timed out and the locator wasn't found.

                Comment


                • #9
                  Yes this firedrv.waitForElementClickable(titleInput); returns me false. The redefining part I will change. I have given the same string generated in the recording by using the selenium IDE .
                  Last edited by Navas; 13th Mar 2018, 11:11.

                  Comment


                  • #10
                    If the locator works in Selenium IDE, but waitForElementClickable() fails in WebDriver, that means the page isn't loading properly or loading differently than in Selenium IDE. If you can run WebDriver against an older version of Firefox, then perhaps while waitForElementClickable() is waiting to time out, you could open Selenium IDE and try to capture the locator to verify it's the same?

                    Comment

                    Working...
                    X