15
17

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 webdriverメソッド~PHP~

Last updated at Posted at 2019-04-03

SeleniumをPHPで書くときのメソッドのまとめがほしいなと思ったので
よく使うであろう基本的なメソッドをまとめました。

メソッド一覧

指定したURLへ遷移

$driver->get("URL");

ウィンドウを閉じる

$driver->close();

全てのウィンドウを閉じる

$driver->quit();

一つもどる

$driver->navigate()->back();

一つ進む

$driver->navigate()->forward();

ブラウザを更新する

$driver->navigate()->refresh();

URLを取得する

$driver->getCurrentURL();

タイトル取得

$driver->getTitle();

スクリーンショット取得

$driver->takeScreenshot("場所とファイル名");

要素取得

$driver->findElemenet(WebDriverBy::id("ID"));
$driver->findElemenet(WebDriverBy::name("NAME"));
$driver->findElemenet(WebDriverBy::tagName("TAGNAME"));
$driver->findElemenet(WebDriverBy::cssSelector("CSSSELECTOR"));
// 複数取得
$driver->findElements(WebDriverBy::className("CLASSNAME");

要素をクリック

$driver->findElement(WebDriverBy::id("ID"))->click();

要素のテキストを取得

$driver->findElement(WebDriverBy::id("ID"))->getText();

テキスト入力

$driver->findElement(WebDriverBy::id("ID"))->sendKeys("入れたいテキスト");

入力された値をクリア

$driver->findElement(WebDriverBy::id("ID"))->clear();

属性の取得

$driver->findElement(WebDriverBy::id("ID"))->getAttribute("属性");

要素が表示されるまで待つ

$driver->wait(10)->until(
  WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::id("ID"))
);

また更新します。

15
17
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
15
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?