Announcement

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

    sclocator syntax without explicit ID

    I need to select elements that don't have explicit IDs, and have figured out that xpath is a dead end. Newer versions of our application are built with IDs, but I still need to test legacy versions that are a mix of old and new elements.

    We use a Java bin that uses SmartClientWebBrowser and SeleneseTestCaseParser to read html test case files.

    The two elements in question are the text fields used for login - they are the only two input fields on the page:
    <td style="vertical-align: top;" align="left"><input class="loginTextField" style="width: 300px;" id="" type="text"></td>
    <td style="vertical-align: top;" align="left"><input class="loginTextField" style="width: 300px;" type="password"></td>

    When I use the Selenium IDE it offers //input[@id=''] as the selection syntax, which of course doesn't work when I pass it to the SC class (more detailed queries also fail: //input[@class='loginTextField' and @type='text']). When I right click on other elements that have IDs, the proper sclocator syntax is shown and I can interact with them as expected.

    How do I select these elements?

    I've read these two:
    https://www.smartclient.com/smartgwt...gSelenium.html
    https://www.smartclient.com/smartgwt.../AutoTest.html

    And can see this example:
    //DynamicForm[ID="autoTestForm"]/item[name=textField||title=textField||value=test||index=0||Class=TextItem]/element

    But don't understand enough to apply this to my situation (this is my first foray into automated testing). Appreciate any insight you can offer.

    edit: the <td> I'm trying to select is nested inside a div that has an ID of "isc_C" - it appears to be a WidgetCanvas wrapping plain html. Structure is div->div->tbody->tr and finally the two td that I want. Can paste the block if it will help. I thought maybe I could select the parent item using the id/class/index, then 'walk' to my desired elements, but this syntax is beyond me.
    Last edited by dingodan; 8 Feb 2018, 00:34.

    #2
    What release are you using? What version of Firefox? You say the XPath queries don't work when using our extensions, but do you mean both in Selenium IDE and the SeleneseRunner/SmartClientWebDriver emulation tool?

    Can you provide an example script, and -if possible - a public page we can hit with that script to see the issue?

    Comment


      #3
      I'm using chrome 64 with the 2.35 driver to execute the tests, but Firefox ESR 52.6 with the Selenium IDE to make the tests.

      The dependencies for the test module include isomorphic_webdriver 5.1p, selenium-java 2.53.1 and htmlparser 2.1. I can find smartgwt-5.0p in the repo for this release. Not sure if that sufficiently answers your question - is there's something I've missed please let me know.

      The classes I'm using are an internal one: CustomSmartClientChromeDriver, that extends SmartClientChromeDriver, which extends SmartClientWebDriver. The purpose of the CustomSCCD class appears to be to let me pass in a ChromeOptions instance, and to add some custom 'waitForText' methods, which I am not using in these tests (just type, sendKeys, and waitForElementPresent/Clickable).

      The example query I used (//input...) works in the Selenium IDE, but any element location method other than scLocator= fails when I pass it to the CustomSCCD class. The exception is:
      !!! Problem executing: type(By.scLocator: //input[@class='loginTextField' and @type='text']/ByScLocator, testuser/String)
      org.openqa.selenium.NoSuchElementException: //input[@class='loginTextField' and @type='text']
      ...
      Driver info: driver.version: SmartClientWebDriver
      at com.isomorphic.webdriver.ByScLocator.findElement(ByScLocator.java:82)

      The application isn't exposed to the internet, but I can paste the test script (first two pass, third throws exception.):
      Code:
      <tbody>
      <tr>
          <td>open</td>
          <td>/app-core/</td>
          <td></td>
      </tr>
      <tr>
          <td>waitForElementPresent</td>
          <td>scLocator=//autoID[Class=Dialog||index=0||length=1||classIndex=0||classLength=1||roleIndex=0||roleLength=1||title=Login||scRole=alertdialog]/item[0][Class=&quot;Canvas&quot;]/</td>
          <td></td>
      </tr>
      <tr>
          <td>type</td>
          <td>//input[@class='loginTextField' and @type='text']</td>
          <td>testuser</td>
      </tr>
      <tr>
          <td>type</td>
          <td>//input[@class='loginTextField' and @type='password']</td>
          <td>testpassword</td>
      </tr>
      <tr>
          <td>sendKeys</td>
          <td>//input[@class='loginTextField']</td>
          <td>${KEY_ENTER}</td>
      </tr>
      <tr>
          <td>waitForElementClickable</td>
          <td>scLocator=//Button[ID=&quot;logoutBtn&quot;]/</td>
          <td>scLocator=//Button[ID=&quot;logoutBtn&quot;]/</td>
      </tr>

      Comment


        #4
        It looks like you're using SGWT 5.1p, which is several releases old now - you should probably upgrade to a newer release, to benefit from improvements already present. Note that you may encounter issues running your tests under Chrome when they were written originally in Firefox, since both in the drivers and in our layer, browser-specific bugs and limitations on some commands may be present. If that approach is due to lack of support for newer Firefox versions in Selenium v2, note that we have switched to Selenium v3 in SGWT 12.0d which is available for download.

        No matter which SGWT release you choose, it's important to use the same Selenium JARs shipped with that release. In the case of browser drivers, which we don't ship, the driver release notes should indicate which Selenium and browser versions they're compatible with - so it's up to you to follow that guidance.

        For the problem you've reported above, the supported use case from Java is really just calling the various SeleneseRunner APIs, rather than extending internal classes - SeleneseTestCaseParser is marked as an internal class. However, we believe the issue here is just that xpath locators aren't being properly resolved to a By.ByXPath class instance when the SmartClientWebDriver API call is invoked. We've ported some improvements that were already in SGWT 12.0d back to SGWT 5.1p and newer releases to allow such locators to be parsed properly by SeleneseRunner. That should be in the nightly builds dated 2018-02-12 and beyond.

        Finally, note that scLocators should be used wherever possible, especially when referring to SmartClient widgets, in preference to xpath locators, as our documentation discusses, since xpath locators are more fragile than scLocators.

        Comment


          #5
          Thank you for an informative and useful response. I need to take this back to dev to get a newer version of SGWT into our legacy branch. It might take a while, but I will report back with results.

          Comment

          Working...
          X