如何在selenium webdriver中将Web浏览器从Firefox更改为Chrome / Opera / IE / Safari? [英] How to change web browser from Firefox to Chrome/Opera/IE/Safari in selenium webdriver?

查看:463
本文介绍了如何在selenium webdriver中将Web浏览器从Firefox更改为Chrome / Opera / IE / Safari?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将浏览器从firefox更改为使用selenium webdriver的Chrome / Opera / IE?请引导步骤以及代码段。

How to change browser from firefox to Chrome/Opera/IE working in selenium webdriver? Please guide in steps and also with the code snippet.

如果您对上述任何浏览器有答案,请回复。

Please reply if you have answer for any of the browsers mentioned above.

我在这方面读了很多但无法正确链接。

I read out a lot on this but could not link it properly.

推荐答案

首先你需要将正确的驱动程序导入项目/类。

First of all you need to import the proper drivers into the project/class.

喜欢

import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

等。

你需要为你需要的broswer创建新的Web驱动程序。

The you need to create new Webdrivers for the broswer you need.

喜欢

WebDriver driver = new FirefoxDriver();
WebDriver driver = new InternetExplorerDriver();
WebDriver driver = new ChromerDriver();

等。

< b>注意:
在单次测试中使用不同的浏览器/驱动程序很困难。你可以为每个浏览器使用类似的测试并维护一个测试套件(即使用一个驱动程序并在测试中导入并为其他浏览器维护类似的测试)或者你可以使用一些配置文件或excel来获取你想要的浏览器测试运行。您可能想要探索
http://htmlunit.sourceforge.net/ 进行无头测试。

有关OperaDriver的信息,请访问: - https://github.com/operasoftware/operadriver/

And information about OperaDriver can be found here: - https://github.com/operasoftware/operadriver/

这篇关于如何在selenium webdriver中将Web浏览器从Firefox更改为Chrome / Opera / IE / Safari?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆