2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Selenium関係のメモ

Last updated at Posted at 2016-05-29

Slenium関係の自分用メモです。

インストール関係

「Exception in thread "main" java.lang.NoClassDefFoundError」

public static void main(String[] args) {
    WebDriver driver = new FirefoxDriver();
    driver.get("https://www.google.co.jp/");
}

上記ソースを実行すると、下記のエラーが発生しました。

Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
	at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
	at java.lang.Class.getMethod0(Class.java:3018)
	at java.lang.Class.getMethod(Class.java:1784)
	at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 7 more

原因: mavenのscopeが「test]のため、実行時にSeleniumのクラスが使えなかった。

修正前pom.xml

pom.xml
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.53.0</version>
            <scope>test</scope>
        </dependency>

修正後pom.xml

pom.xml
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.53.0</version>
        </dependency>

反省: mavenの勉強もしておきましょう。


org.openqa.selenium.remote.unreachablebrowserexceptionの発生

以下のコードで、unreachablebrowserexceptionが発生しました。

FirefoxDriver driver = new FirefoxDriver();

原因: Firefoxのバージョンが新しすぎた

  • selenium version: 2.53.0
  • Firefox version: 47

Firefox versionを46にしたら、動いた。

反省: Seleniumで使うブラウザは、「自動更新」しないようにしましょう。

driver.quitでエラーが発生

driver.quitで、次のエラーが発生しました。

Selenium WebDriver RuntimeException:Process refused to die after 10 seconds, and couldn't taskkill it: Unable to find executable for: taskkill

taskkillが見つからないとのこと。
環境変数PATHC:\Windows\system32を追加したら、解決しました。

http://stackoverflow.com/questions/30776502/selenium-webdriver-runtimeexceptionprocess-refused-to-die-after-10-seconds-and

IE関係

IE8でcssセレクタのnth-of-typeが使えない

下記のHTMLに対して、「2番目のボタンをクリックする」という操作をCSSセレクタのnth-of-typeを使って実装しました。

test-target.html
<div id="button-area">
  <button>ボタン1</button>
  <button>ボタン2</button>
  <button>ボタン3</button>
</button>
selenium-sample.java
//2番目のボタンをクリックする
driver.findElement(By.cssSelector("#button-area button:nth-of-type(2)")).click();

IE8では動きませんでした。IE8ではnth-of-typeというCSSがサポートされていないので、使えないようです。

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?