LoginSignup
1
0

More than 5 years have passed since last update.

Selenium でリンクをたどる (Java)

Posted at

Selenium でリンクをたどるサンプルです。
次のプログラムを Java で書いてみました。
Selenium でリンクをたどる (Python)

follow_link.java
// -----------------------------------------------------------------------
/*
    follow_link.java

                Sep/21/2018
*/
// ----------------------------------------------------------------------- 
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;

public class follow_link {

// ----------------------------------------------------------------------- 
public static void main(String[] args) {
    System.err.println ("*** 開始 ***");

    String url = "https://ekzemplaro.org";

    WebDriver driver = new FirefoxDriver();
    driver.get(url);

    WebElement tag = driver.findElement(By.id("ekzemplaro"));

    tag.click();

    tag = driver.findElement(By.linkText("English"));

    tag.click();

    System.err.println ("*** 終了 ***");
}

// ----------------------------------------------------------------------- 
}

// ----------------------------------------------------------------------- 
Makefile
follow_link.class: follow_link.java
    javac follow_link.java -cp ./client-combined-3.14.0.jar 
clean:
    rm -f follow_link.class

実行方法

export CLASSPATH=.:./client-combined-3.14.0.jar:./guava-26.0-jre.jar:./okhttp-3.11.0.jar:./okio-2.0.0.jar:./kotlin-stdlib-1.2.60.jar:./commons-exec-1.3.jar
#
java follow_link
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0