【问题标题】:Cannot find element in the popup window with Selenium Webdriver使用 Selenium Webdriver 在弹出窗口中找不到元素
【发布时间】:2013-01-16 20:46:12
【问题描述】:

我在 Java 中使用 InternetExplorerDriver 和 Selenium Webdriver。

我加载了一个 URL,它同时打开了另一个具有登录框的窗口。 使用here提到的方法

我可以选择所需的窗口,也可以选择send keys 进入焦点框。

popup.getKeyboard().sendKeys("yeuiryuiryweuiryeuiyterui");

但是,以下内容:

popup.findElement(By.id("userName")).sendKeys("user")

无法找到该元素并引发Element-not-found 异常(类似于此)。

我哪里弄错了?

【问题讨论】:

  • 什么是getKeyboard()方法?
  • 它用于将键发送到焦点元素。

标签: java dom automation popup selenium-webdriver


【解决方案1】:

我会建议你尝试使用 xpath

String locator = "//*[@class='Class name of user name text box'and text()='if any']"

可以通过firebug找到用户名

List<WebElement> element = Driver.driver.findElements(By.xpath(locator));   

然后在 web 元素上使用单击功能,对密码执行相同操作,然后使用 Driver.selenium.click(xpath); 直接单击登录,并提供登录按钮的 xpath,以防 id 不存在。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-26
    相关资源
    最近更新 更多