selenium “无效参数:‘句柄’必须是一个字符串”错误的Microsoft Edge和如何添加“w3c:FALSE”功能?

yzuktlbb  于 2022-11-10  发布在  其他
关注(0)|答案(1)|浏览(161)

我收到一个**“无效参数:‘Handle’必须是字符串”Error forMicrosoft Edge**。
我认为当我添加**“w3c:False”**能力时,这个问题就会得到解决。

  • w3c:FALSE代码块:*
if (CustomRunner.deviceThreadLocal.get().getBrowser().equals(BrowserType.EDGE)) {

  EdgeOptions edgeOptions = new EdgeOptions();
  edgeOptions.setCapability("w3c", false);
  DesiredCapabilities capabilities = new DesiredCapabilities();
  capabilities.setCapability(EdgeOptions.CAPABILITY, edgeOptions);
  edgeOptions.merge(capabilities);

}
  • EdgeOptions.java:*
package org.openqa.selenium.edge;

import static org.openqa.selenium.remote.CapabilityType.PAGE_LOAD_STRATEGY;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.MutableCapabilities;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.CapabilityType;

import java.util.Objects;

public class EdgeOptions extends MutableCapabilities {

  public EdgeOptions() {
    setCapability(CapabilityType.BROWSER_NAME, BrowserType.EDGE);
  }

  @Override
  public EdgeOptions merge(Capabilities extraCapabilities) {
    super.merge(extraCapabilities);
    return this;
  }

  public void setPageLoadStrategy(String strategy) {
    setCapability(PAGE_LOAD_STRATEGY, Objects.requireNonNull(strategy));
  }

  public EdgeOptions setProxy(Proxy proxy) {
    setCapability(CapabilityType.PROXY, proxy);
    return this;
  }
}

但是当我想要添加这种能力时,我无法运行代码,因为EdgeOptions.java中没有能力

我如何解决这个问题?

egmofgnx

egmofgnx1#

我不知道如何使用handle,但对于添加w3c:false的问题,这是由于Selify服务器版本的原因。当您使用Selify服务器3.141.59时,会出现该问题。我使用的是Selify服务器4.0.0测试版2,它与以下代码配合得很好:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;

public class Edgedisablew3c {
    public static void main(String[] args) { 
         System.setProperty("webdriver.edge.driver", "Your_path_here\\msedgedriver.exe"); 
         EdgeOptions edgeOptions = new EdgeOptions();
         DesiredCapabilities capabilities = new DesiredCapabilities();

         capabilities.setCapability(EdgeOptions.CAPABILITY, edgeOptions);
         capabilities.setCapability("w3c", false);
         edgeOptions.merge(capabilities);       

         WebDriver driver = new EdgeDriver(edgeOptions); 
         driver.get("https://www.google.com");

         System.out.println(capabilities.getCapability("w3c")); //Getting the value of w3c to verify it.

         driver.close();
         driver.quit();
    }
}

相关问题