Finding parent element in Protractor

0 votes
<label class="radio inline check">

            <input class="input ng-new ng-valid" name="BookType" required="" type="radio">

            <!---->

            <!---->
            Fiction
</label>

<label class="radio inline check">   

            <input class="input ng-new ng-valid" name="BookType" required="" type="radio">

            <!---->

            <!---->
            NonFiction
</label>

<label class="radio inline check">

            <input class="input ng-new ng-valid" name="BookTypeReal" required="" type="radio">

            <!---->

            <!---->
            Fiction
</label>

<label class="radio inline check">   

            <input class="input ng-new ng-valid" name="BookTypeReal" required="" type="radio">

            <!---->

            <!---->
            Fantasy
</label>

If I use

element.all(locator).filter(filterFn

the text returned is empty.

How can I go to parent element <label> to get the text?

label[class="radio inline check"] 

returns 60 elements where more than one getText will return same text so it won't be unique.

input[name="BookType"] 

returns two elements where each element is unique.

Mar 26, 2018 in Selenium by nitinrawat895
• 10,670 points
910 views

1 answer to this question.

0 votes

To get the parent element, you can use XPath's ancestor:

.//*[@name='BookType']/ancestor::label
answered Mar 26, 2018 by nsv999
• 5,090 points

Related Questions In Selenium

0 votes
1 answer

(Protractor) Finding specific row in ng-table by text

Try this Return the filtered elements before trying ...READ MORE

answered May 10, 2018 in Selenium by Samarpit
• 5,130 points
3,964 views
0 votes
1 answer

Protractor waiting for element to be in DOM

You should be able to use browser.wait together with ...READ MORE

answered Sep 17, 2018 in Selenium by Meci Matt
• 9,420 points
587 views
0 votes
1 answer

How to use JavaScript in selenium to click an Element?

Executing a click via JavaScript has some ...READ MORE

answered Apr 13, 2018 in Selenium by Shubham
• 13,290 points
12,045 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,090 points
555 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
890 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
553 views
0 votes
2 answers

Finding an element in Selenium

Hi, ​both find_element_by_xpath(xpath) and find_element(By.XPath, xpath) serve the ...READ MORE

answered Aug 23 in Selenium by Abha
• 22,870 points
120 views
0 votes
2 answers

Unable to Click on an Element in Selenium (Python) even after finding it.

Here, I give you working script which ...READ MORE

answered Sep 19, 2018 in Selenium by Priyaj
• 56,520 points
7,356 views