【问题标题】:selenium not being able to find element unless i move my mouse over to that elementselenium 无法找到元素,除非我将鼠标移到该元素上
【发布时间】:2012-12-09 11:44:05
【问题描述】:

我正在使用 Selenium RC 来自动化一些第三方网站,并面临上传文件按钮的一些问题。

该按钮出现在页面上,但 Selenium 无法找到并单击该元素。我试图等待该元素出现在页面上,因此在解决问题后,我知道如果我在等待该元素时手动将鼠标移到该按钮上,Selenium 会找到该元素。

这是我的代码 sn-p。

public void testBox() throws Exception{
    selenium.setTimeout("10000000000");
    selenium.open("/files");
    selenium.click("id=login_button_credentials");
    selenium.waitForPageToLoad("150000");
    while(!selenium.isElementPresent("id=upload_split_arrow")) {
        Thread.sleep(10);
    }

    selenium.click("id=upload_split_arrow");
    while(!selenium.isElementPresent("id=upload_file1")) {
        Thread.sleep(10);
    }

    selenium.click("id=upload_file1");
    Thread.sleep(10000000);
}

谁能为此建议一些解决方法?

【问题讨论】:

  • 不打开文件上传控件,把文件的路径发给元素即可。
  • 嗨阿兰这就是我正在做的而不是点击它我正在使用 selenium.type("id=upload_file1","D:\\Downloads\\testcases\\testcases\\SalesforceAccounts.java ");我正在使用上述类型命令,但这不是问题,问题是 selenium 无法找到该元素,一旦我将鼠标移到该元素,它就会找到它。

标签: selenium selenium-rc


【解决方案1】:

在使用“点击”命令之前使用“焦点”。 它可能会达到目的。

    selenium.focus("id=upload_file1");
    selenium.click("id=upload_file1");

【讨论】:

  • 嗨 HemChe 即使是为了聚焦,它也应该能够首先找到那个按钮,直到我手动将鼠标移到那个按钮上。
  • 即使在 selenium.focus 我得到元素未找到异常
猜你喜欢
  • 2015-03-06
  • 2021-11-13
  • 1970-01-01
  • 2018-03-31
  • 2016-01-22
  • 1970-01-01
  • 1970-01-01
  • 2022-07-05
  • 2021-10-19
相关资源
最近更新 更多