代码改变世界

selenide总结

2019-07-11 18:17  AnnaWong  阅读(586)  评论(0编辑  收藏  举报

selenide官方api:  https://selenide.org/documentation.html

 

 启动浏览器

 1 package StartDriver;
 2 import static com.codeborne.selenide.Selenide.* ;
 3 import org.testng.annotations.Test;
 4 public class TestStartDriver {
 5 @Test
 6 public void testFirefox(){
 7 //selenide默认使用Firefox浏览器
 8 open("https://www.baidu.com/");
 9     }
10 @Test void testChrome(){
11 //指定Driver 的存放目录
12 System.setProperty("webdriver.chrome.driver","c:/driver/chromedriver.exe");
13 //指定需要启动的浏览器类型
14 System.setProperty("selenide.browser", "Chrome");
15 //System.setProperty("selenide.browser", "Ie");
16 //打开测试地址
17 Selenide.open("https://www.baidu.com/");
18     }
19 }

 

元素定位

八大元素定位,其中id、name、xpath 能完成95%的元素定位

但是一般推荐使用css而不是xpath
其原因是:
1CSS locator比XPath locator速度快,特别是在IE下面(IE没有自己的XPath 解析器(Parser))他比xpath更高效更准确更易编写,美中不足是根据页面文字时略有缺陷没有xpath直接)