4

I am trying to execute a functional test using Selenium 2 and PHPUnit.

In the class 'Selenium2TestCase.php', I found this code:

class PHPUnit_Extensions_Selenium2TestCase_SessionCommand_Click extends PHPUnit_Extensions_Selenium2TestCase_Command
{
    const LEFT = 0;
    const MIDDLE = 1;
    const RIGHT = 2;

    public function __construct($argument, PHPUnit_Extensions_Selenium2TestCase_URL $url)
    {
        if (is_null($argument)) {
            $jsonParameters = NULL;
        } elseif (!is_scalar($argument) || !in_array($argument, array(
            self::LEFT, self::RIGHT, self::MIDDLE
        ))) {
            throw new BadMethodCallException('Wrong parameter for click(): expecting 0, 1 or 2.');
        } else {
            $jsonParameters = array('button' => $argument);
        }

        parent::__construct($jsonParameters, $url);
    }

    public function httpMethod()
    {
        return 'POST';
    }
}

But I don't know how to use it to simulate a right click.

0
1
public function testItemClick() {

    $this->url($this->pageUrl);
    sleep(2);
    $element = $this->byCssSelector('blabla');
    $this->moveto($element);
    $this->click(PHPUnit_Extensions_Selenium2TestCase_SessionCommand_Click::RIGHT);
    $this->assertStringStartsWith(...

}
0

The php-webdriver project on GitHub has a function contextClick() which fires a right click.

0

You can use contextMenu method:

$this->contextMenu(//table[@id='yourID']);

See http://release.seleniumhq.org/selenium-core/1.0.1/reference.html#contextMenu

2
  • This is for the old Selenium RC, this does not work in the latest webdriver, I think. Mar 12 '14 at 21:12
  • thx Niels, I updated the answer with link to newest release.
    – rukbat
    Mar 13 '14 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.