Last active
December 3, 2020 00:04
-
-
Save RyosukeKamei/cd84bb975739296aab7835bc2ef878a3 to your computer and use it in GitHub Desktop.
【α版】Seleniumの要素を特定する(ベスト?)プラクティス xpath記法とdata属性の合わせ技 ref: http://qiita.com/RyosukeKamei/items/8230f566665c2ca1ac34
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const webdriver = require('selenium-webdriver'); | |
const By = webdriver.By; | |
driver.findElement(By.xpath("//a[@data-selenium='login']")).click(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
By.xpath("//a[@data-selenium='login']"); // data属性 おすすめ | |
By.xpath("//a[@id='login']"); // idでも指定可能 | |
By.xpath("//a[@class='button login_button']"); // classでも指定可能 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
By.id("login"); // ID | |
By.className("login_button"); // CSSクラス名 | |
By.xpath("//a[@data-selenium='login']"); // xpath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a id='login' class='button login_button' data-selenium='login'>ログイン</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment