Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 86 lines (74 sloc) 2.066 kB
cdf7e83 Initial commit
Austin Matzko authored
1 <?php
2
3 class WebDriver extends SearchContext
4 {
5 public function addCookie( $name = '', $value = null )
6 {
7 $args = array(
8 'cookie' => array(
9 'name' => $name,
10 'value' => $value,
11 'path' => '/',
12 'domain' => $this->_domain,
13 'secure' => true,
14 )
15 );
16
17 $response = $this->_post_request( $this->_request_url . '/cookie', $args );
18 }
19
20 public function close()
21 {
22 $response = $this->_delete_request( $this->_request_url . '/window' );
23 if (
24 isset( $response->value->class ) &&
25 (
26 'org.openqa.selenium.NoSuchWindowException' == $response->value->class
27 )
28 ) {
29 throw new Exception( $response->value->localizedMessage );
30 }
31 }
32
33 public function findElementBy( $using = 'xpath', $expression = null )
34 {
35 if ( ! in_array(
36 $using,
37 array(
38 'id',
39 'xpath',
40 )
41 ) ) {
42 throw new InvalidArgumentException( 'Invalid "using" argument for findElementBy.' );
43 }
44
45 $args = array(
46 'using' => $using,
47 'value' => $expression,
48 );
49 $response = json_decode( $this->_post_request( $this->_request_url . '/element', $args ) );
50
51 if ( ! isset( $response->value ) || ! isset( $response->value->ELEMENT ) ) {
52 if (
53 isset( $response->value->class ) &&
54 (
55 'org.openqa.selenium.NoSuchElementException' == $response->value->class ||
56 'org.openqa.selenium.StaleElementException' == $response->value->class ||
57 'org.openqa.selenium.XPathLookupErrorException' == $response->value->class
58 )
59 ) {
60 throw new Exception( $response->value->localizedMessage );
61 } else {
62 throw new Exception( 'No matching element found.' );
63 }
64 }
65
66 $element = new WebElement( null, null, $this->_request_url );
67 $element->session_id = $this->_session_id;
68 $element->session_element_id = $response->value->ELEMENT;
69
70 return $element;
71 }
72
73 public function get( $url = '' )
74 {
75 if ( empty( $url ) ) {
76 throw new InvalidArgumentException( 'Requested URL cannot be empty.' );
77 }
78
79 $args = array(
80 'url' => $url,
81 );
82
83 $response = $this->_post_request( $this->_request_url . '/url', $args );
84 }
85 }
Something went wrong with that request. Please try again.