0

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();
    }
}
Anjani Kumar
  • 396
  • 1
  • 5
  • 23

3 Answers3

0

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.

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-remote-driver</artifactId>
    <version>4.0.0-alpha-3</version>
</dependency>
Krishna
  • 198
  • 6
0

enter image description here

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

Anjani Kumar
  • 396
  • 1
  • 5
  • 23
  • 2
    Please don't hide important information in images. They don't get indexed and therefore the text they show can't be searched. It can't be copied, either. Some users won't even be able to read the text due to poor contrast or use of adaptive technologies like screen readers. – ChrisGPT was on strike May 30 '21 at 14:15
  • Link to where the screenshot is from? – Csaba Toth Jul 14 '23 at 06:14
-1

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.