admin 管理员组文章数量: 1184232
本人软件测试工程师一枚,工作6年,功能测试,接触过selenium,也接触过Jmeter,但都只是入门级别,不是深入了解,最近打算往全栈测试工程师发展,因为大学学过Java,所以自学先从selenium框架+java学起,记笔记是为了监督自己和整理一下自己遇到的问题。希望自己能坚持住!!
先搭建环境,首先安装JDK(网上有教程,我安装的版本是jdk-8u201-windows-x64),打开eclipse(这个是免安装版),然后新建Java Project,创建完项目导入selenium包,下载网址https://www.seleniumhq/download/(我下载的是selenium-java-3.141.59),然后尝试打开Firefox,可是只能打开浏览器,无法自动输入网址,后来查资料是因为selenium版本与Firefox不兼容导致,又重新卸载安装火狐N次,火狐版本降到很低才能打开,索性尝试打开Chrome和IE,没想到能成功,果断放弃Firefox,使用Chrome和IE,IE11对应的驱动下载网址https://selenium-release.storage.googleapis/index.html,Chrome对应的驱动下载网址http://chromedriver.storage.googleapis/index.html,驱动要与浏览器版本相对应才可以。
IE浏览器版本IE11,对应驱动版本IEDriverServer_x64_2.39.0
Chrome浏览器版本78,对应驱动版本78.0.3904.70
亲测可以用
具体代码如下:
package selenium3;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class test001 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(“webdriver.ie.driver”,“C:\\Program Files (x86)\\Internet Explorer\\IEDriverServer.exe”);
WebDriver driver = new InternetExplorerDriver();
driver.get(“http://www.baidu”);
System.out.println(“成功打开网址”);
}
}
package selenium3;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class test002 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty(“webdriver.chrome.driver”,“C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe”);
WebDriver driver = new ChromeDriver();
driver.get(“http://www.baidu”);
System.out.println(“成功打开网址”+driver.getCurrentUrl());
}
}
但是IE只能打开浏览器,无法对元素进行操作,个人还是觉得谷歌最好用,最后用谷歌进行自动化测试的学习。
版权声明:本文标题:selenium3.141+java打开浏览器,但是无法自动输入网址问题 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1768018921a3526667.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论