0

I am trying to get an array of elements using xpath and load the results into an array and then perform assertCount(). Here is the code I that I have. I am new to this and I am not sure why elementList is empty?

<?php

require_once('Base.php');

class FollowupTest extends Test_Base {

    protected $session = null;

    /**
    * Asserts that the count of list elements on the page is equal
    * to three utilizing an xpath expression.
    */
    public function testCountListElements() {
        $elementsList = $this->session->elements('xpath', '//li');
        $this->assertCount(3, sizeof($elementList));
    }
}
3
  • Could you provide more details? What Selenium Server are you using? Are you using a library (like PHPUnit_Selenium extension) for Selenium API? What is Test_Base? Is it a custom class from you? Commented Jun 7, 2013 at 19:46
  • I am using selenium server 2.25.0 (Webdriver). Test_Base is a class in phpunit. It is not custom. $elementList should be an array and I need to load it with the elements retrieved from $this->session->elements('xpath', '//li') Commented Jun 21, 2013 at 17:59
  • Well, I'm no expert, but I think you should be extending Selenium2TestCase. session() is available on that class. I think the manual should provide a good start: phpunit.de/manual/current/en/selenium.html. Commented Jun 24, 2013 at 17:28

1 Answer 1

1

If you extend PHPUnit_Extensions_Selenium2TestCase, you can count elements with this structure:

$elements = $this->elements($this->using('xpath')->value('//li'));
$this->assertEquals(3, count($elements));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.