2013-02-20 3 views
0

Google 자동 도움말 드롭과 같은 자동 생성 드롭을 작성했으며 그 결과 값을 출력으로 인쇄하려고했습니다. 셀레늄 WebDriver에Selenium Web Driver : findElementsBy() 함수가 PHP-webdriver-bindings에서 오류를 반환했습니다.

제가 결합 당 같이

<?php 
require_once 'www/library/phpwebdriver/WebDriver.php'; 
class PHPWebDriverTest extends PHPUnit_Framework_TestCase { 
protected $webdriver; 

    protected function setUp() { 
     $this->webdriver = new WebDriver("localhost", 4444); 
     $this->webdriver->connect("firefox"); 
    } 

    protected function tearDown() { 
    // $this->webdriver->close(); 
    } 
    public function testgooglesearch() {       
    $this->webdriver->get("http://google.com"); 
    $element=$this->webdriver->findElementBy(LocatorStrategy::name, "q");   
    $element->sendKeys(array("selenium")); 
    $result=$this->webdriver->findElementsBy(LocatorStrategy::xpath,"//*[@id=\'gsr\']/table/tbody/tr/td[2]/table/tbody/tr[*]/td/"); 
    echo $countresult=count($result); 

    } 
} 
?> 

아래 주어진 작성한 코드 우리 findElementsBy() 함수를 사용하여 가지고 XPath는 로케이터와 일치 여러 요소를 잡을 findElementsBy() 함수는 배열을 반환한다고 가정합니다. 그래서 배열 길이를 계산하려고 할 때 오류가 반환됩니다.

오류 : 개체가 아닌 속성을 얻으려고합니다.

내가 어떻게 진행할 수 있는지 알려주세요.

+2

** 어떤 ** 오류 아래에 주어진? – Arran

+0

배열이 인쇄되고 있다는 웹 위에 예외가 표시됩니다. – John

+0

PHP 바인딩은 무엇입니까? 꽤 많은 것들이 있으며 Selenium 개발팀이 공식적으로 지원하지 않습니다. – Ardesco

답변

6

마지막으로 문제의 해결책을 직접 찾을 수 있습니다. 내 주요 모토는 자동차의 가치를 인쇄했다

테스트의 속도 .as 인 시험의 실행 속도가 빠른이었다 가장 큰 문제는 이렇게 "findElementsBy"기능이 작동 할 수 없습니다 아래

드롭 생성 정확히.

그래서 제대로 작동 할 수 있도록 함수 바로 전에 sleep 명령을 사용했습니다.

나를 위해 제대로 작동 코드는

<?php 
require_once "/phpwebdriver/WebDriver.php"; 
class WebdriverTest extends PHPUnit_Framework_TestCase 

{ 
    protected $webdriver; 

    protected function setUp() 
    { 

$this->webdriver=new WebDriver("localhost", 4444); 

    $this->webdriver->connect("firefox"); 
    } 

    protected function tearDown() { 
     $this->webdriver->close(); 
    } 

    public function testSearch() 
    { 
    $this->webdriver->get("http://google.com");   

     $element=$this->webdriver->findElementBy(LocatorStrategy::name,"q"); 
    $element->sendKeys(array("selenium")); 

sleep(2); 
    $result=$this->webdriver->findElementsBy(LocatorStrategy::xpath,"//td[@class='gssb_a gbqfsf']"); 
    $countresult=count($result); 
    echo "Records Count = ". $countresult ."\n"; 
     $x=1; 
    $y=0; 
    echo "\n"; 
    while($y<$countresult) 
     { 
     $output=$result[$y]->getText(); 
    echo $output."\n"; 
     $x++; 
     $y++; 
     } 

    $r=$this->webdriver->findElementBy(LocatorStrategy::xpath,"//div[@class='gbqlca']"); 
    $r->click(); 



    } 



} 
?> 
0

유용한 정보입니다.

클릭 here

는 참고 : 위의 구현은 자바 셀레늄 바인딩입니다.

+0

@samtoshsharma 링크에 대한 감사하여 "PHP-webdriver-바인딩"내가 그 링크를 확인하지만, 매우 도움이되지 PHP를 사용하는 PHP - webdriver - 바인딩에 대한 한 것입니다. . – John

+0

@ 존 : 예, 저는 자바로 작업 할 때 php-webdriver-bindings를 모르겠습니다. 나는 당신의 문제를 해결할 아이디어를 줄 수 있기 때문에 그 링크를 제안합니다. – Santoshsarma

관련 문제