Skip to content

Instantly share code, notes, and snippets.

@RyosukeKamei
Last active December 3, 2020 00:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyosukeKamei/cd84bb975739296aab7835bc2ef878a3 to your computer and use it in GitHub Desktop.
Save RyosukeKamei/cd84bb975739296aab7835bc2ef878a3 to your computer and use it in GitHub Desktop.
【α版】Seleniumの要素を特定する(ベスト?)プラクティス xpath記法とdata属性の合わせ技 ref: http://qiita.com/RyosukeKamei/items/8230f566665c2ca1ac34
const webdriver = require('selenium-webdriver');
const By = webdriver.By;
driver.findElement(By.xpath("//a[@data-selenium='login']")).click();
By.xpath("//a[@data-selenium='login']"); // data属性 おすすめ
By.xpath("//a[@id='login']"); // idでも指定可能
By.xpath("//a[@class='button login_button']"); // classでも指定可能
By.id("login"); // ID
By.className("login_button"); // CSSクラス名
By.xpath("//a[@data-selenium='login']"); // xpath
<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