Search code examples
javaseleniumselenium-webdrivertestngwebdriver-manager

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


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();
    }
}

Solution

  • 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.