How to get data from an object returned by Selenium with php?

0

I'm using Selenium + Chrome WebDriver and php to wipe data from a website, and for that I need to make a condition with the width of a column of a table on that site. I do this with the following code:

$td3 = $driver ->findElement(WebDriverBy::xpath('/html[1]/body[1]/form[1]/div[2]/div[1]/table[2]/tbody[1]/tr[5]/td[3]')) -> getSize();

Only Selenium returns me the size in object form. As shown in two forms below.

With var_dump :

  

object (Facebook \ WebDriver \ WebDriverDimension) # 19 (2) {["height": "Facebook \ WebDriver \ WebDriverDimension": private] = > int (38) ["width": "Facebook \ WebDriver \ WebDriverDimension": private] = > int (0)}

With print_r :

  

Facebook \ WebDriver \ WebDriverDimension Object ([height: Facebook \ WebDriver \ WebDriverDimension: private] => 38 [width: Facebook \ WebDriver \ WebDriverDimension: private] = >

I want only 0, which is the width of the element. How do I get there?

Addendum1: When I try to use the getWidth() function. This error is generated (that I only have access by the error.log file of php 7):

  

PHP Fatal error: Uncaught Error: Call to undefined method

main} \ n thrown in /var/www/html/inpi/crawler.php on line 92

Addendum2: There is no css defined in the tag so I can use getAttribute('width') . But I tried and it did not work out.

    
asked by anonymous 22.03.2018 / 16:46

1 answer

1

According to "documentation" , the object Facebook\WebDriver\WebDriverDimension has two methods for capturing the value of the properties:

  • getHeight() to return height
  • getWidth() parap returns the width

As the height and width properties are private (only the class has access) , then you need to use the above methods to get this value, for example:

$td3 = $driver->findElement(WebDriverBy::xpath('/html[1]/body[1]/form[1]/div[2]/div[1]/table[2]/tbody[1]/tr[5]/td[3]'))->getSize();

var_dump($td3->getHeight()); //Output: 38
var_dump($td3->getWidth()); //Output: 0
    
22.03.2018 / 16:53