selenide与selenium的区别见https://github.com/codeborne/selenide/
配置
添加依赖,添加Demo示例,在github上可以找到。
使用
执行mvn clean test
即可
问题
- 设置谷歌浏览器的驱动参数,如--no-sandbox,--headless等。设置方法是在环境变量或使用-Dkey=value传值,key要以-Dchromeoptions.args开头,我现在使用的一个参数示例就是
-Dchromeoptions.args=--no-sandbox,--headless,--disable-infobars,--window-size=1900x1080
,最开始使用--headless时会出现页面元素打不到的情况,后来添加了--window-size参数后就正常了,注意--window-size参数的值应该是“宽x高”,使用selenide时造成不要使用“宽,高”,看下源码com.codeborne.selenide.webdriver.ChromeDriverFactory#transferChromeOptionsFromSystemProperties就知道了。