【问题标题】:Access new window elements through selenium RC通过 selenium RC 访问新的窗口元素
【发布时间】:2014-03-12 08:42:40
【问题描述】:

我是 Selenium 的新手。这是我的第一次尝试。我想通过 Selenium RC 访问新窗口中的元素。我有一个带有超链接的页面,单击它将打开新页面。我想在新窗口中输入用户名和密码元素。 html代码是

员工登录

新的页面元素是用于登录的“emailAddress”和“password”。

我的硒代码是

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");

}

首先我尝试了正常的方法,但无法识别元素。然后我尝试使用 open window 和 selectWindow 选项,它通过像

这样的错误
"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)"

有人告诉我,使用 Selenium RC 是不可能的。它只能通过 Selenium Webdriver 来实现。这是真的吗?

请帮忙, 提前致谢。

【问题讨论】:

  • 谢谢 Nilesh 和 sircapsalot。我有一个 ID 为“empLogin”的锚标记。 http://myneo.neo.local/user/login" >员工登录。我用谷歌搜索了具体问题,发现只有 WebDriver 才有可能。无论如何感谢您的回答。

标签: selenium automation selenium-rc


【解决方案1】:

Selenium RC 不再维护,我建议您改用WebDriverSelenium RC 是一个 Javascript 应用程序,其中 WebDriver 使用浏览器 Native API。因此,使用 WebDriver 的浏览器交互与真实用户的操作非常接近。在我看来,WebDriver 的 API 也更直观且易于使用。我在你的问题中没有看到 HTML,但你可以从这样的开始,

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

【讨论】:

  • 是的,Nilesh,我尝试了很多方法。但没有一个成功。所以我有转移到 Selenium WebDriver。 @sircapsalot:非常感谢您的快速回复。
【解决方案2】:

我会说,按照@nilesh 所说的去做。使用 Selenium WebDriver。

回答您的具体问题:

您在这一行失败了,因为您没有指定选择器策略。

sel.click("empLogin");

如果id 属性是empLogin 则执行

sel.click("id=empLogin");

您还可以使用其他选择器策略:

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

您可以查看完整列表here

由于同样的问题,你也会在这里失败:

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

在这些字段之前放置一个选择器策略前缀。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-25
    • 2019-08-24
    • 2023-04-05
    • 2019-01-11
    • 2019-01-06
    • 1970-01-01
    • 2021-06-15
    相关资源
    最近更新 更多