Find nth link #3853

Open
gimler opened this Issue Dec 19, 2016 · 2 comments

Projects

None yet

2 participants

@gimler
Contributor
gimler commented Dec 19, 2016

What are you trying to achieve?

I have a list of buttons and must click the nth button.

Workaround:

$this->click("form:nth-child(1) input[name=form_edit]");

I would prefer to find all buttons by 'form_edit' and then use the nth.

Is there a function in WebDriver Module to find elements by selector?

@DavertMik
Member

Is there a function in WebDriver Module to find elements by selector?

Yes, but the implementation you look for can be made in a custom helper using _findElements method. This should return an array of RemoteWebElement instances of facebook/webdriver. You can match the exact one you need and click it

@gimler
Contributor
gimler commented Dec 20, 2016

Thanks. Problem with _findElements is that they don't match name attribute.

So i must use this workaround ;(

/**
 * Find all matching elements
 * @param $locator
 * @return []
 */
public function findElements($locator)
{
    $elements = $this->webDriverModule->_findElements($locator);
    if (empty($elements))
    {
        $elements = $this->webDriverModule->_findElements('[name=' . $locator . ']');
    }

    return $elements;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment