首页 > 解决方案 > 有没有办法在 driver.manage().timeouts() 方法之外设置隐式超时?

问题描述

我继续收到“元素不可交互”错误,我认为这是由于在页面上执行操作后链接加载速度不够快。隐式驱动程序等待似乎不起作用,看起来它甚至没有设置?

我正在像这样设置隐式等待驱动程序:(页面加载似乎没有帮助)

driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

功能 [{mobileEmulationEnabled=false, timeouts={implicit=0, pageLoad=300000, script=30000},hasTouchScreen=false,平台=XP,acceptSslCerts=false,goog:chromeOptions={debuggerAddress=localhost:63891},acceptInsecureCerts=false,webStorageEnabled=true,browserName=chrome,takeScreenshot=true,javascriptEnabled=true,platformName=XP,setWindowRect =true, unexpectedAlertBehaviour=ignore, applicationCacheEnabled=false, rotatable=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387), userDataDir=C:\Users\jxg262\AppData\Local\Temp\scoped_dir2012_6} =true,unhandledPromptBehavior=ignore,pageLoadStrategy=normal,strictFileInteractability=false,databaseEnabled=false,handlesAlerts=true,版本=71.0.3578.98,browserConnectionEnabled=false,proxy=Proxy(),nativeEvents=true,locationContextEnabled=true,cssSelectorsEnabled=true }]

这似乎表明没有设置隐式。难道我做错了什么?有没有办法在别处设置它?

标签: javaselenium-chromedriver

解决方案


隐式超时是 chrome 服务器超时,所以在启动 Chrome 之前尝试设置它,像这样

ChromeOptions chromeOptions = new ChromeOptions();

Map<String, Integer> timeouts = new HashMap<>();
timeouts.put("implicit", 3000);
chromeOptions.setCapability("timeouts", timeouts);

webDriver = new ChromeDriver(chromeOptions);

推荐阅读