Announcement

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

    [Selenium2] problem identifying elements using scLocator in Java scripts

    Hi all,

    I'm using Selenium2/Webdriver to test my application but I'm facing some problems with the scLocator.

    My Selenium don't recognize elements identified by the scLocator.

    Is there any solution to this problem?

    below is un example of my Java code:

    Code:
    import com.thoughtworks.selenium.Selenium;
    import org.openqa.selenium.*;
    import org.openqa.selenium.htmlunit.*;
    import org.openqa.selenium.firefox.*;
    import org.openqa.selenium.chrome.*;
    import org.openqa.selenium.ie.*;
    import org.testng.annotations.*;
    import static org.testng.Assert.*;
    
    public class T2 {
    
           WebDriver driver;
           Selenium selenium;
    
           @BeforeMethod
           public void startSelenium() {
                   driver = new FirefoxDriver();
                   selenium = new WebDriverBackedSelenium(driver, "the url");
           }
    
           @AfterMethod
           public void stopSelenium() {
                   driver.close();
           }
    
           @Test
           public void testT2() {
                   selenium.open("the url");
                   selenium.type("scLocator=//Window[ID=\"isc_SignInViewImpl_0\"]/
    item[0]
    [Class=\"DynamicForm\"]/item[name=email||title=Email||index=1||
    Class=TextItem]/element", "login");
                   selenium.type("scLocator=//Window[ID=\"isc_SignInViewImpl_0\"]/
    item[0][Class=\"DynamicForm\"]/item[name=password||value=none||
    index=2||Class=PasswordItem]/element", "password");
                   selenium.click("scLocator=//IButton[ID=\"isc_IButton_0\"]/
    icon");                selenium.click("scLocator=//ListGrid[ID=
    \"isc_NavigationPaneSection_1_1\"]/body/row[id=14||0]/
    col[fieldName=name||1]");
                   selenium.click("scLocator=//IButton[ID=\"isc_IButton_2\"]/");
                   selenium.waitForPageToLoad("30000");
           }
    
    }
    Regards,

    SmartGWT 2.4
    Firefox 3.6.14
    Selenium 2.0b2
    TestNG 5.14.1

    #2
    Make sure you're loading the Selenium extensions as indicated in the instructions. Beyond that, we'd need a test case that includes the actual widget creation code to comment.

    Comment


      #3
      Originally posted by Isomorphic
      Make sure you're loading the Selenium extensions as indicated in the instructions.
      What is said in the instructions is how to use the extensions with Selenium IDE but nothing about how to use it with Selenium2 (the newer version of Selenium RC).
      I followed the instructions and It works fine with the IDE.
      But when I export my test case into Selenium2 nothing works.

      Originally posted by Isomorphic
      Beyond that, we'd need a test case that includes the actual widget creation code to comment.
      Excuse me but I don't understand what you mean.
      Can you explain more please?

      Comment


        #4
        There are two files, both are loaded in the IDE, one is also loaded with Selenium Core.

        Comment


          #5
          Originally posted by Isomorphic
          There are two files, both are loaded in the IDE, one is also loaded with Selenium Core.
          Yes, I know that there are two files.

          But, I don't know how to use the second one with my Selenium.

          Just notice that the version (2.0b2) I'm using is a little bit different from the Selenium Rc (version 1).

          Comment


            #6
            Badrodoja,
            I'm testing the beta3 of selenium2 to see how hard it's going to be the migration of our tests. To handle the scLocators I used addLocationStrategy, in something like this:

            Code:
            Selenium selenium = new WebDriverBackedSelenium(driver, baseUrl);
            selenium.addLocationStrategy("scLocator", "return inWindow.isc.AutoTest.getElement(locator);");
            I haven't tested it throughly, but I could execute some clicks.

            Comment


              #7
              Originally posted by elopio
              Badrodoja,
              I'm testing the beta3 of selenium2 to see how hard it's going to be the migration of our tests. To handle the scLocators I used addLocationStrategy, in something like this:

              Code:
              Selenium selenium = new WebDriverBackedSelenium(driver, baseUrl);
              selenium.addLocationStrategy("scLocator", "return inWindow.isc.AutoTest.getElement(locator);");
              I haven't tested it throughly, but I could execute some clicks.
              Thank you for your replay elopio.

              I have alreaady resolve that by rewriting some function of Selenium.

              I admit that It was a little bit hard, but It's working now.

              I'm now using the beta 3 too.

              Comment


                #8
                Could you share your solution, please?

                Comment


                  #9
                  Originally posted by elopio
                  Could you share your solution, please?
                  Yes, of course.

                  I'll do It this weekend and I hope It will help.

                  Comment


                    #10
                    Dear Badrodoja,

                    Can you please share the solution. I am facing the exact problem.

                    Thanks in advance.

                    Comment


                      #11
                      You can implement the use of the scLocators directly in your java code. Like this :
                      Code:
                      public By byScId(final String locator) {
                      
                      		  final String id = locator
                      		      .replaceAll("'", "")
                      		      .replaceAll("\"", "");
                      
                      		  return new By() {
                      		    public List<WebElement> findElements(SearchContext ignored) {
                      		      throw new UnsupportedOperationException("findElements");
                      		    }
                      		  
                      		    public WebElement findElement(SearchContext context) {
                      		      if (!(context instanceof JavascriptExecutor)) {
                      		        throw new NoSuchElementException("context must implement JavascriptExecutor");
                      		      }
                      		      
                      		      JavascriptExecutor js = (JavascriptExecutor) context;
                      		      
                      		      return (WebElement) js.executeScript(
                      		          "var o = window[arguments[0]]; " +
                      		          "if (!o) { return null; } " +
                      		          "var scLocator = '//' + o.getClassName() + '[ID=\"' + arguments[1] + '\"]'; " +
                      		          "return window.isc.AutoTest.getElement(scLocator)",
                      		          id, locator);
                      		    }
                      		  };
                      		}

                      Comment

                      Working...
                      X