在 Ubuntu 16.04 中安装 Selenium 并使用 java 代码进行检查

Viv*_*oor 5 java selenium

我想制作一个 java 程序(GUI),它会在点击按钮自动填充网站中的用户名和密码。我是 Java 网络概念的新手。一位朋友告诉我使用selenium,因为这会很容易,但我无法成功使用它(尝试过的代码如下所示)。我正在使用Ubuntu 16.04操作系统并使用gedit编写源代码。任何帮助将不胜感激。

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

public class pextax implements ActionListener {
    JFrame frame;
    JButton button;
.
.
.
public void GUI() throws Exception  {
    button = new JButton("Click to open PEXTAX official website");
    button.addActionListener(this);

.
.
.
}

public void actionPerformed (ActionEvent event) {
    if(event.getSource()==button)   {
        try {
            DesiredCapabilities capabilities = DesiredCapabilities.firefox();
            capabilities.setCapability("marionette", true);
            WebDriver driver = new FirefoxDriver(capabilities);

            driver.get("https://www.pextax.com");
            driver.manage().window().maximize();

            WebElement username = driver.findElement(By.name("username"));
            WebElement password = driver.findElement(By.name("password"));

            username.sendKeys("123456789");
            password.sendKeys("1234");

        }catch(Exception e) {   }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

vivek@vivek-HP-Notebook:~$ javac pextax.java

pextax.java:4: 错误: 包 org.openqa.selenium 不存在 import org.openqa.selenium.By; ^

pextax.java:5: 错误:包 org.openqa.selenium 不存在 import org.openqa.selenium.WebDriver; ^

pextax.java:6: 错误:包 org.openqa.selenium 不存在 import org.openqa.selenium.WebElement; ^

pextax.java:7: 错误:包 org.openqa.selenium.firefox 不存在导入 org.openqa.selenium.firefox.FirefoxDriver; ^

pextax.java:8: 错误:包 org.openqa.selenium.support.ui 不存在导入 org.openqa.selenium.support.ui.ExpectedCondition; ^

pextax.java:9: 错误:包 org.openqa.selenium.support.ui 不存在 import org.openqa.selenium.support.ui.WebDriverWait;