question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sublocators using xpath locators not behaving the same as css locators

See original GitHub issue

Bug report

  • Node Version: 8.15.1
  • Protractor Version: 5.4.2
  • Angular Version: 1.5
  • Browser(s): Chromium
  • Operating System and Version macOS Mojave 10.14.6

Example DOM:

<html>
    <elementA>
    </elementA>

    <elementB>
        <elementA>
        </elementA>
    </elementB>
</html>

Behavior observed:

// these ones return both instances of "elementA" 
element(by.xpath('//elementB')).element(by.xpath('//elementA'));
element(by.xpath('//elementB')).all(by.xpath('//elementA'));

// these ones work as documented, only returning the "elementA" nested inside "elementB"
element(by.xpath('//elementB')).$('elementA');
element(by.xpath('//elementB')).$$('elementB');

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
Jayasankar-mcommented, Jan 1, 2020

@costanza5813 can u try with .// foreg:

    element(by.xpath('//elementB')).element(by.xpath('.//elementA'));
    element(by.xpath('//elementB')).all(by.xpath('.//elementA'));
0reactions
Jayasankar-mcommented, Jan 12, 2020

@praveendvd You can directly use as $('ul').$('li')

It finds child anywhere under Ul not directly under . If the structure is like ul>span>il , still the locator finds the element . I need the equivalent of ./ Xpath

@praveendvd I don’t think CSS has a way to refer the current node like that

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does this xpath work but the css selection doesn't [locator ...
I'm working on switching from xpath to css for my selectors where possible. This worked in xpath: //ul[contains(@id,'district-switcher')].
Read more >
XPath vs CSS Selector: The Difference and How to Choose
We'll discuss the syntax in greater depth shortly. Advantages of Using XPath. XPath allows you to navigate up the DOM when looking for...
Read more >
CSS Selector vs XPath: Your Pocket Cheat Sheet - testRigor
Automation scripts can handle most locators using both XPath and CSS selectors. Best practices while writing locator expressions. Typically, CSS ...
Read more >
Examples with xpath and Css (ID, Name, Text and Links)
It is very simple to locate elements if the HTML DOM has 'id' or 'name' and they are the safest locators to use....
Read more >
Which locator do you use with Selenium: CSS or XPath?
Don't forget that not only performance is better with CSS locators, it's the compatibility too that matters. We are testing on a multi...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found