我是Selenium的新手。这是我的第一次尝试。我想通过Selenium RC访问新窗口中的元素。我有一个带有超链接的页面,单击它将打开新页面。我想在新窗口中输入用户名和密码元素。Html 代码是
员工登录
新的页面元素是用于登录的"电子邮件地址"和"密码"。
我的硒代码是
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");
}
首先,我尝试使用正常方法,但无法识别元素。然后我尝试使用打开窗口并选择窗口选项,其中它通过错误,例如
"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)"
有人告诉我,硒RC是不可能的。它只能通过Selenium Webdriver实现。是真的吗?
请帮忙,提前谢谢。
Selenium RC
不再维护,我建议您改用WebDriver
。 Selenium RC
是一个Javascript应用程序,其中WebDriver使用浏览器的本机API。因此,使用 WebDriver 的浏览器交互接近真实用户的操作。在我看来,WebDriver的API更加直观和易于使用。我在你的问题中没有看到 HTML,但你可以从这样的东西开始,
WebDriver driver = new FirefoxDriver();
WebElement login = driver.findElement(By.id("empLogin"));
login.click();
<</div>
div class="one_answers">我会说,按照@nilesh所说的去做。 使用Selenium WebDriver。
不过,回答您的具体问题:
您在此行失败,因为您没有指定选择器策略。
sel.click("empLogin");
如果id
属性empLogin
则执行
sel.click("id=empLogin");
您还可以使用其他选择器策略:
css=
id=
xpath=
link=
etc...
您可以在此处查看完整列表。
由于相同的问题,您也将在此处失败:
sel.type("emailAddress", "kiranxxxxx@xxxxxx.com");
sel.type("password", "xxxxxxxx");
在这些字段之前放置一个选择器策略前缀。
sel.type("name=emailAddress", "kiranxxxxx@xxxxxx.com");
sel.type("name=password", "xxxxxxxx");