无需进入由Selify-Java自动化的QR-Whatsapp Web

原学程将引见无需退进由Selify-Java主动化的QR-Whatsapp Web的处置办法,这篇学程是从其余处所瞅到的,而后减了1些海外法式员的疑问与解问,愿望能对于您有所赞助,佳了,上面开端进修吧。

无需进入由Selify-Java自动化的QR-Whatsapp Web 教程 第1张

成绩描写

我正在测验考试在第1个以后消除两维码过程。

我经由过程Web启动法式运转Whatsapp的代码:

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:whatsupsrcmainresourceschromedriver.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/");

}

}

当Web阅读器第1次翻开时,我正在脚机上履行两维码例程。履行Java剧本代码时激发异常。

但是我支到了下1个异常:

Exception in thread "main" org.openqa.selenium.NoSuchSessionException: no such session

假如我测验考试保留Cookie,则Cookie散为空(没法保留所有Cookie,仍没有晓得缘由)。

怎样在第1次以后跳过QR的此进程?假如有人晓得怎样跳过它,乃至1次也没有做,这也是有赞助的(但是我以为如今太易了)。

提早感谢!

推举谜底

应用设置装备摆设文件!

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument(r"user-data-dir=D:PythonMemoryWebWhatsAppBot")

navegador = webdriver.Chrome(
executable_path="D:PythonWebWhatsAppBotchromedriver.exe", chrome_options=options)
navegador.get("https://web.whatsapp.com/")

佳了闭于无需退进由Selify-Java主动化的QR-Whatsapp Web的学程便到这里便停止了,愿望趣模板源码网找到的这篇技巧文章能赞助到年夜野,更多技巧学程不妨在站内搜刮。