本文主要向大家介绍了JAVA语言+selenium自动化测试框架记录,通过具体的内容向大家展示,希望对大家学习JAVA语言有所帮助。
selenium:是一套软件工具,用来支持不同的自动化测试方法。
selenium2,selenium1,seleniumIDE,selenium-grid
定位页面元素:
name,LinkText,particalLinkText,cssSelector,xpath,className,tagName,js方法。
举个用ID的例子,其他的只要改对应的id那里的位置就行了
//设置驱动所在位置
System.setProperty("webdriver.chrome.driver", "D:\\driver1\\chromedriver.exe");
//引用火狐浏览器驱动
WebDriver driver = new ChromeDriver();
//打开禅道界面
driver.get("https://www.zentao.net/user-login.html");
WebElement name = driver.findElement(By.id("account"));
name.sendKeys("afyuchang");
WebElement pw = driver.findElement(By.id("password"));
pw.sendKeys("ychandchandao");
WebElement but = driver.findElement(By.id("submit"));
but.submit();
xpath(XML path)定位:
程序在前面的博客。https://blog.csdn.net/afishhhhhh/article/details/79654092
1.绝对路径/html/body/p/input[@value="查询"]
2.页面获取,右键点控件选COPY XPATH
3.相对路径://input[@value="查询"]
4.使用索引号定位 //input[2]
5.使用页面属性定位 //img[@alt='p1-img1']
6.模糊定位 //img[starts-with(@alt,'p')]
//img[contains(@alt,'g1')]
7.text(),文本定位 //*[text()='百度搜索']? ?
//a[contains(text(),'搜索')]
填到输入框里:
element.sendKeys("test1111")
清空输入框:
element.clear()
获取输入框内容:
element.getAttribute("value")
小tips:
abc
abc为一个段落,下一个标签另起一行。
.isEnable();
获取活设置一个值,该值只是是否UI中启用了此元素,这是依赖项属性。
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注编程语言JAVA频道!