试图通过IE取消使用capability(capability.setCapability(CapabilityType.ACCEPT_ssl_CERTS,true(的ssl证书来运行以下代码。
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.apache.jmeter.samplers.SampleResult;
io.github.bonigarcia.wdm.WebDriverManager.iedriver().setup()
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
WebDriver driver = new InternetExplorerDriver(capabilities)
def wait = new WebDriverWait(driver, 20);
driver.get('https://google.com/');
WDS.sampleResult.sampleStart();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//input[@name='q']")));
WDS.sampleResult.sampleEnd();
最终出现以下错误。
2020-10-11 09:43:21,585 ERROR o.a.j.p.j.s.JSR223Sampler: Problem in JSR223 script iecONFIG, message: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: CapabilityType for class: Script63
javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: CapabilityType for class: Script63
有人知道如何处理SSL证书吗?并以无头模式运行IE?
我看不出你在哪里声明CapabilityType类的导入,你要么需要添加下一行:
import org.openqa.selenium.remote.CapabilityType
到脚本的开头
或更换
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true)
带有
capabilities.setCapability(org.openqa.selenium.remote.CapabilityType.ACCEPT_SSL_CERTS, true)
我认为你将无法在无头模式下运行Internet Explorer,唯一的选择是将JMeter作为系统服务运行,这样浏览器就不会出现在你的桌面上,如果需要,请参阅Jenkins文章中的无头执行硒测试以获取更多信息