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>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

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']"));
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352