Is it possible to get next sibling using cssContainingText in Protractor

前端 未结 3 1797
被撕碎了的回忆
被撕碎了的回忆 2021-01-02 19:58

Is it possible to get the next sibling by using by.cssContainingText()

Example: HTML code is like below:

相关标签:
3条回答
  • 2021-01-02 20:45

    What if you would get it in one go using by.xpath():

    element(by.xpath('//div[@class="text-label" and . = "SomeText"]/following-sibling::div'))
    

    Or, you can combine it with cssContainingText():

    element(by.cssContainingText('div.text-label','SomeText')).element(by.xpath('following-sibling::div'))
    
    0 讨论(0)
  • 2021-01-02 20:52

    You could use the node.nextSibling selector. Check out this article

    0 讨论(0)
  • 2021-01-02 20:54

    Using Xpath selectors is not a better choice as it slows down the element finding mechanism.

    I have designed a plugin to address this specific issues: protractor-css-booster

    The plugin provides some handly locators to find out siblings in a better way and most importantly with CSS selector.

    using this plugin, you can directly use:

    var elem = await element(by.cssContainingText('div.text-label','SomeText')).nextSibling();
    

    or, use booster as by-locator

    var elem = element(by.cssContainingText('div.text-label','SomeText')).element(by.followingSibling('div'));
    

    Hope, it will help you...

    0 讨论(0)
提交回复
热议问题