Selenium安装-如何在Java中安装Selenium

2021-06-14  本文已影响0人  IT赶路人

Selenium的安装步骤。

安装Selenium的过程包括3个步骤,即:

1.安装Java

2.安装Eclipse IDE

3.安装Selenium WebDriver

Selenium支持各种编程语言,如Java、Python、C# 、Perl、RubyTM等。Java是Selenium使用最广泛的语言之一。让我们开始了解Java的安装过程。安装Java所需的第一步是配置Java环境,以便稍后可以使用Java codes来驱动Selenium。

安装Java

按照以下步骤完成Java安装。


7.png

** 转到Java下载页面,然后单击Java Platform(JDK)选项。

** 转到“开始”并搜索“SYSTEM”

8.png

安装Eclipse

12.png

** 导航到以下url-https://www.eclipse.org/downloads/并根据您的系统架构选择下载链接-(32位或64位)并下载。

** 下载结束后,解压压缩文件并保存到任意目录。根文件夹是Eclipse。


14.png

安装Selenium Web驱动

** 应该开始下载‘Selenium-server-Standalone-x.y.z.jar’。将此JAR保存在“C:Selenium”中。


16.png

** 解压zip文件,保存在您的Selenium文件夹中。

21.png

package Edureka;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class FirstSeleniumScript {
public static void main(String[] args) throws InterruptedException{
System.setProperty("webdriver.chrome.driver", "C:Selenium-java-edurekachromedriver_win32chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("https://login.yahoo.com/");
driver.findElement(By.xpath("//input[@id='login-username']")).sendKeys("edureka@yahoo.com");
}
}

上一篇 下一篇

猜你喜欢

热点阅读