【问题标题】:How to identify a color of a locator(Button/Label) using css locator in selenium? [duplicate]如何在 selenium 中使用 css 定位器识别定位器(按钮/标签)的颜色? [复制]
【发布时间】:2013-05-02 09:02:36
【问题描述】:

我正在运行一些自动化脚本,这些脚本将保存从服务器下载的文件并将我的文件从下载文件夹复制到用户特定的文件夹和 保存后,“保存”按钮将变为颜色:红色(之前为蓝色)。有没有办法使用 selenium +Java 对其进行测试? 我目前使用 WebdriverBackedSelenium 来开发我的脚本。

   //Current Sample Code Snippet:
     if(selenium.isElementPresent("css=Submit_Button"))
 {
      selenium.click("css=submit_Button");
 }

 //Expected Code Snippet:

 if(selenium.isElementPresent("css=Submit_Button"))
 {
      if( /* something like colorof("css=Submit_Button")=="RED"*/ )
          selenium.click("css=submit_Button");
      else
          System.out.print("\n Already Processed:");
 }

【问题讨论】:

    标签: java css file selenium


    【解决方案1】:

    你可以试试这个:

    File source = new File("H:\\work-temp\\file");
    File desc = new File("H:\\work-temp\\file2");
    try {
        FileUtils.copyDirectory(source, desc);
    } catch (IOException e) {
        e.printStackTrace();
    }
    

    【讨论】:

      【解决方案2】:

      http://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/IOUtils.html
      复制方法!

      我认为你做这件事可以使用其他方法。例如:python或shell!

      【讨论】:

        【解决方案3】:

        如果您有 Java 7,那么您可以使用 Files#copy 直接将文件从源复制到目标!

        如果你没有 Java 7,你可以从 Apache Commons 那里获得帮助,它提供了 FileUtils#copyFile 用于文件复制!

        【讨论】:

          【解决方案4】:

          我了解您使用硒?如果不是,则忽略此答案。

          您也可以将浏览器首选项设置为您最终想要保存文件的文件夹。根据您使用 selenium 自动化的浏览器,您必须稍微不同地设置首选项。对于 Firefox,您可以这样做

          FirefoxProfile profile = new FirefoxProfile(); 
          profile.setPreference("browser.download.dir", "c:\\YOUR\\PATH"); 
          profile.setPreference("browser.download.folderList", 2); 
          profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
            "application/pdf,text/csv"); 
          WebDriver driver = new FirefoxDriver(profile); 
          

          或者你使用像 powder-monkey 这样的东西和 selenium 来获取你的下载......

          【讨论】:

            猜你喜欢
            • 2023-03-30
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-09-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2014-12-20
            相关资源
            最近更新 更多