How to fix Selenium DesiredCapabilities giving Error 'not resolved to a type' while using with WebdriverManager and ChromeOptions

huangapple go评论68阅读模式
英文:

How to fix Selenium DesiredCapabilities giving Error 'not resolved to a type' while using with WebdriverManager and ChromeOptions

问题

如何修复在使用WebdriverManager和ChromeOptions时出现Selenium DesiredCapabilities错误:'not resolved to a type'

package pack.tests;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testng.annotations.BeforeTest;
import org.openqa.selenium.remote.CapabilityType;
// 错误:无法解析导入的org.openqa.selenium.remote.CapabilityType
import org.openqa.selenium.remote.DesiredCapabilities;
// 错误:无法解析导入的org.openqa.selenium.remote.DesiredCapabilities
import io.github.bonigarcia.wdm.WebDriverManager;
public class TestGuru99Login {
    @BeforeTest
    public void Setup() {
        WebDriverManager.chromedriver().setup();
        ChromeOptions option = new ChromeOptions();
        option.addArguments("--test-type");
        option.addArguments("--disable-popup-bloacking");
        option.addArguments("--incognito");
        DesiredCapabilities chrome = DesiredCapabilities.chrome();
        /* 错误
        此行处有多个标记 - 无法解析DesiredCapabilities - 无法将DesiredCapabilities解析为类型 */
        chrome.setJavascriptEnabled(true);
        chrome.setCapability(ChromeOptions.CAPABILITY, option);
        WebDriver driver = new ChromeDriver(option);
        // 错误:类型不匹配:无法从ChromeDriver转换为WebDriver
        driver.get("https://toolsqa.com");
        driver.quit();
    }
}
英文:

How to fix Selenium DesiredCapabilities giving Error 'not resolved to a type' while using with WebdriverManager and ChromeOptions

package pack.tests;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testng.annotations.BeforeTest;
import org.openqa.selenium.remote.CapabilityType;
//Error The import org.openqa.selenium.remote.CapabilityType cannot be resolved
import org.openqa.selenium.remote.DesiredCapabilities;
//Error The import org.openqa.selenium.remote.DesiredCapabilities cannot be resolved
import io.github.bonigarcia.wdm.WebDriverManager;
public class TestGuru99Login{
@BeforeTest
public void Setup() {
	    WebDriverManager.chromedriver().setup();
	    ChromeOptions option = new ChromeOptions();
	    option.addArguments("--test-type");
	    option.addArguments("--disable-popup-bloacking");
	    option.addArguments("--incognito");
	    DesiredCapabilities chrome = DesiredCapabilities.chrome();
	    /*Error
	    Multiple markers at this line - DesiredCapabilities cannot be resolved -
	    * DesiredCapabilities cannot be resolved to a type*/
	    chrome.setJavascriptEnabled(true);
	    chrome.setCapability(ChromeOptions.CAPABILITY, option);
	    WebDriver driver = new ChromeDriver(option);
	    //Error:Type mismatch: cannot convert from ChromeDriver to WebDriver
	    driver.get("https://toolsqa.com");
	    driver.quit();
    }
}

答案1

得分: 0

org.openqa.selenium.remote.DesiredCapabilities
上述内容来自 Selenium 远程驱动模块。您可以将以下内容添加到您的 POM.xml 中并尝试使用。根据与其他 Selenium 模块的兼容性,您可以更改 "version" 数字。

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-remote-driver</artifactId>
    <version>4.0.0-alpha-3</version>
</dependency>
英文:

org.openqa.selenium.remote.DesiredCapabilities
Above one is coming from the selenium remote driver module. You can add the following in your POM.xml and try out. You can change the "version" number based on your compatibility with other selenium module.

&lt;dependency&gt;
    &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;
    &lt;artifactId&gt;selenium-remote-driver&lt;/artifactId&gt;
    &lt;version&gt;4.0.0-alpha-3&lt;/version&gt;
&lt;/dependency&gt;

答案2

得分: 0

这个解决方案在我的情况下似乎有效。是否还有其他人遇到这个问题,所有其他上述的解决方案都没有起作用。

英文:

How to fix Selenium DesiredCapabilities giving Error 'not resolved to a type' while using with WebdriverManager and ChromeOptions

This solution seems to be working in my case. Anybody else facing this issue, all other above solutions are not working.

答案3

得分: -1

这是在将外部JAR文件添加到ModulePath时发生的情况。
解决方案:
从节点"Modulepath"中移除外部JAR文件。选择节点"Classpath",然后添加外部JAR文件。检查是否已导入了Selenium JAR文件。

英文:

This happens when you have added the external jars in the ModulePath.
Solution:
enter code hereRemove the external jars from the node "Modulepath". Select the node "Classpath" then add the external jars. Check selenium jar is imported.

huangapple
  • 本文由 发表于 2020年8月27日 01:21:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/63602714.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定