Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid xpath from Selenium when using find in Element subclass #3

Closed
MPV opened this issue May 15, 2013 · 6 comments
Closed

Invalid xpath from Selenium when using find in Element subclass #3

MPV opened this issue May 15, 2013 · 6 comments

Comments

@MPV
Copy link

MPV commented May 15, 2013

Hi,
Is this a bug in BehatPageObjectExtension?

We get this error:

exception 'Selenium\Exception' with message 'Unexpected response from Selenium server:
ERROR: Invalid xpath [2]: (///descendant-or-self::*[@id = 'del_name_4'])[1]' 
in /Users/vs/MyProjectNameHere/vendor/alexandresalome/php-selenium/src/Selenium/Driver.php:87

And this is the type of code we use:

use SensioLabs\Behat\PageObjectExtension\PageObject\Element;

class TestModule extends Element
{
    protected $selector = array('xpath' => '//div[@id="mod"]');

    public function doSomething()
    {
        $element = $this->find('css', 'del_name_4');
    }

}
@jakzal
Copy link
Member

jakzal commented May 15, 2013

It's not a bug. Most likely element with an id "del_name_4" doesn't exist on the page you requested.

@MPV
Copy link
Author

MPV commented May 15, 2013

Hi Jakub,
Thanks for taking your time to review this.

If I'm not fully mistaken (I'll take the time to review it again real soon):

We had the same test code before (but without extending Element (instead
extending NodeElement, and without setting xpath for the instance). The
same find() call worked then (i.e. finds the #del_mod_4 element). Also,
switching to findById() works fine. It's just find() (which I understand
uses the custom xpath scoping from Element) that gives this issue. For many
cases it could be okay to switch to findById temporarily, but I find (no
pun intended) that find() still has many separate use cases.

I have also tried setting either xpath or CSS selector/locator pairs in
$selector but get the same results.

Also, since it's not the case that null (no NodeElement object) is returned
from the find() method (but instead an error from Selenium about invalid
xpath) – this would lead me to believe there is a problem with generating a
correct xpath, and not with finding an element?

Again, I will take another look at this and see if I can find a possible
culprit, and if I have any ideas on how to solve it. I promise to submit a
pull request if I manage to solve it.

Thanks,
Victor

@jakzal
Copy link
Member

jakzal commented May 15, 2013

Could you paste the related part of the html?

@MPV
Copy link
Author

MPV commented May 20, 2013

Hi @jakzal,
Sorry about the delay. Here's an excerpt of the related part of the HTML:

<div id="mod">
    <div class="message">
        <p>Select a delivery method from the list below.</p>
    </div>
    <!-- Delivery methods -->
    <ul>
        <li id="del_1">...</li>
        <li id="del_4">
            <input type="radio" name="radioDelivery" value="4" id="del_4_radio" class="inputRadio">
            <div class="title col">
                <label for="del_4_radio">
                    <span class="icon icon-tick" aria-hidden="true"></span>
                    <span class="name" id="del_name_4">Delivery method 4</span>
                </label>
            </div>
            <div class="price col" id="del_fee_4">FREE</div>
            <div class="desc col" id="del_desc_4"></div>
            <div class="clear"></div>
        </li>
        ...
    </ul>
</div>

@jakzal
Copy link
Member

jakzal commented May 20, 2013

I can't see anything wrong. I'd rather explicitly specify that del_name_4 is an id: $this->find('css', '#del_name_4'); but I don't think this is an issues since it is actually converted into an id.

I'll have to debug it :)

@jakzal
Copy link
Member

jakzal commented May 28, 2014

@MPV have you solved the issue eventually?

@jakzal jakzal closed this as completed Jun 9, 2014
@SubmeetVet SubmeetVet mentioned this issue Jan 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants