0

In below snippet , how do i select the label using the text "No gateway"? I can use ID , but wanted to select by text.

HTML:

<div class="form-group" style="">
                    <label class="col-xs-12 col-lg-12" for="noGateway" style="background: rgb(204, 136, 136); border: 2px solid red;">
                        <input type="radio" data-ng-model="proxyType" value="noGateway" name="noGateway" id="noGateway" class="ng-valid ng-touched ng-dirty ng-valid-parse" style="">
                        No gateway
                    </label>
                </div>
3
  • <div class="form-group" style=""> <label class="col-xs-12 col-lg-12" for="noGateway" style="background: rgb(204, 136, 136); border: 2px solid red;"> <input type="radio" data-ng-model="proxyType" value="noGateway" name="noGateway" id="noGateway" class="ng-valid ng-touched ng-dirty ng-valid-parse" style=""> No gateway </label> </div> Commented Jun 18, 2018 at 13:22
  • 2
    If you have id, use id. Commented Jun 18, 2018 at 13:36
  • why do you want to select a label ? you may want to click on input ? Commented Jun 18, 2018 at 14:34

1 Answer 1

1

To identify the label using the text No gateway you can use either of the following Java solutions:

  • XPath with contains():

    WebElement element = driver.findElement(By.xpath("//label[contains(.,'No gateway')]"));
    
  • XPath with normalize-space():

    WebElement element = driver.findElement(By.xpath("//label[normalize-space()='No gateway']"));
    
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks it helped , any article that explains A-Z about xpath?
@karthikloganathan Checkout XPath Tutorial. Let me know if you need more references.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.