Skip to content

Commit c6b8ab9

Browse files
committed
Add sample.php
1 parent 17bf5ee commit c6b8ab9

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

example.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
// An example of using php-webdriver.
3+
4+
require_once('lib/__init__.php');
5+
6+
// start Firefox
7+
$host = 'http://localhost:4444/wd/hub'; // this is the default
8+
$capabilities = array(WebDriverCapabilityType::BROWSER_NAME => 'firefox');
9+
$driver = new RemoteWebDriver($host, $capabilities);
10+
11+
// navigate to 'http://docs.seleniumhq.org/'
12+
$driver->get('http://docs.seleniumhq.org/');
13+
14+
// click the link 'About'
15+
$link = $driver->findElement(
16+
WebDriverBy::id('menu_about')
17+
);
18+
$link->click();
19+
20+
// print the title of the current page
21+
echo "The title is " . $driver->getTitle() . "'\n";
22+
23+
// print the title of the current page
24+
echo "The current URI is " . $driver->getCurrentURL() . "'\n";
25+
26+
// Search 'php' in the search box
27+
$input = $driver->findElement(
28+
WebDriverBy::id('q')
29+
);
30+
$input->sendKeys('php')->submit();
31+
32+
// wait at most 10 seconds until at least one result is shown
33+
$driver->wait(10)->until(
34+
WebDriverExpectedCondition::presenceOfAllElementsLocatedBy(
35+
WebDriverBy::className('gsc-result')
36+
)
37+
);
38+
39+
// close the Firefox
40+
$driver->quit();

0 commit comments

Comments
 (0)