I'm trying to eliminate the process of the QR code after the first I'm doing it.
My code to run Whatsapp trough a web driver:
public class DriverTester {
public static void main(String[] args) {
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
ChromeDriverService service = new ChromeDriverService.Builder()
.usingDriverExecutable(new File("C:\\whatsup\\src\\main\\resources\\chromedriver.exe"))
.usingAnyFreePort()
.build();
ChromeOptions options = new ChromeOptions();
options.merge(capabilities);
ChromeDriver driver = new ChromeDriver(service, options);
driver.navigate().to("https://web.whatsapp.com/");
while (driver.findElements(By.xpath(XPaths.autoStartReady)).size() == 0);
LocalStorage localStorage = driver.getLocalStorage();
driver.close();
driver = new ChromeDriver(service, options);
for (String key : localStorage.keySet()){
String value = localStorage.getItem(key);
driver.executeScript("window.localStorage.setItem('"+key+"', '"+value+"');");
}
driver.navigate().to("https://web.whatsapp.com/");
}
}
When the web browser opens for the first time, I'm doing the QR code routine on my phone. The exception was raised while executing the javascript code.
But I'm getting the next exception:
Exception in thread "main" org.openqa.selenium.NoSuchSessionException: no such session
If I'm trying to save the cookies, the cookies set is empty (cannot save any cookie, still don't know why).
How can I skip this process of the QR after the first time? If someone knows how to skip it without even doing it once, it will be also helpful (but I think too much difficult for now).
Thanks in advance!