首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“无效参数:‘句柄’必须是字符串”错误的Microsoft和如何添加"w3c: false“功能?

“无效参数:‘句柄’必须是字符串”错误的Microsoft和如何添加"w3c: false“功能?
EN

Stack Overflow用户
提问于 2021-05-25 15:20:53
回答 1查看 456关注 0票数 0

我得到了一个“无效参数:‘句柄’必须是字符串”错误的Microsoft

我认为,当我添加"w3c:false"功能时,问题将得到解决。

代码块,用于"w3c: false":

代码语言:javascript
复制
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:

代码语言:javascript
复制
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.中没有 capability

我怎样才能解决这个问题?

EN

回答 1

Stack Overflow用户

发布于 2021-05-26 08:08:24

我不知道您如何使用handle,但是对于添加w3c:false的问题,这是selenium服务器版本造成的。当您使用selenium服务器3.141.59时,将出现此问题。我使用Seleniumsever4.0.0 beta 2,它可以很好地处理下面的代码:

代码语言:javascript
复制
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();
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67690957

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档