質問

I am new to Selenium. This is my first attempt. And I want to access the Elements in the new window through Selenium RC. I have a page with a hyper link clicking on it will open new page. I want to enter username and password elements in the new window. Html Code is

Employee Login

and the new page elements are "emailAddress" and "password" for login.

My selenium code is

public static void main(String args[]) throws Exception
{
    RemoteControlConfiguration rc=new RemoteControlConfiguration();
    rc.setPort(2343);
    SeleniumServer se= new SeleniumServer(rc);
    Selenium sel=new DefaultSelenium("localhost",2343,"*firefox","http://neo.local/");
    se.start();
    sel.start();
    sel.open("/");
    sel.windowMaximize();
    //sel.wait(1000);
    sel.click("empLogin");
    //sel.wait(2000);       
    //sel.openWindow("http://myneo.neo.local/user/login", "NewNeo");
    //sel.waitForPopUp("NewNeo", "1000");
    //sel.selectWindow("id=NewNeo");
    Thread.sleep(20000);
    sel.type("emailAddress", "kiranxxxxx@xxxxxx.com");
    sel.type("password", "xxxxxxxx");

}

First I tried with normal approach, where it failed to identify the elements. Then I tried with open window and selectWindow options, where it through errors like

"Exception in thread "main" com.thoughtworks.selenium.SeleniumException: ERROR: Window locator not recognized: id
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:109)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:103)
at com.thoughtworks.selenium.DefaultSelenium.selectWindow(DefaultSelenium.java:377)
at Demo.main(Demo.java:24)"

Some one told me that it is not possible with Selenium RC. It can achieved through Selenium Webdriver only. Is it true?

Please Help, Thanks in Advance.

役に立ちましたか?

解決

Selenium RC is not maintained anymore, I would recommend you to use WebDriver instead. Selenium RC is a Javascript application where as WebDriver uses browsers Native API. Therefore browser interactions using WebDriver are close to what the real user does. Also WebDriver's API is more intuitive and easy to use in my opinion. I don't see HTML in your question, but you could do start with something like this,

WebDriver driver = new FirefoxDriver();
WebElement login = driver.findElement(By.id("empLogin"));
login.click();

他のヒント

I will say, do as @nilesh stated. Use Selenium WebDriver.

Answer to your specific problem though:

You are failing at this line because you are not specifying a selector strategy.

sel.click("empLogin");

If the id attribute is empLogin then do

sel.click("id=empLogin");

There are other selector strategies you can use:

css=
id=
xpath=
link=
etc...

You can see the full list here.

You will also fail here due to the same issue:

sel.type("emailAddress", "kiranxxxxx@xxxxxx.com");
sel.type("password", "xxxxxxxx");

Put a selector strategy prefix before those fields.

sel.type("name=emailAddress", "kiranxxxxx@xxxxxx.com");
sel.type("name=password", "xxxxxxxx");
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top