1

I need to getText from a specific element from the page and these elements only have unique tag "ng-bind="$Gadget.customerSegmentation" and also element location may be changed according to the scenario

I tried below for finding elements but sometimes it working not sometimes no.

@FindBy(xpath = "//div[@ng-bind='$Gadget.customerSegmentation']")
WebElement Customer;

<div class="form_group inline_block" style="width:30%;"> 
  <div class="form_label ng-binding" style="width:30%;">Cust Segmentation:</div> 
   <div class="form_control ng-binding" title="Low" ng-bind="$Gadget.customerSegmentation" style="width:65%;float:right;">Low</div>  
                </div>

can found elements even if the location changed.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
M.Zaky
  • 41
  • 1
  • 10

1 Answers1

0

To identify the element you can use either of the following Locator Strategies:

  • cssSelector:

    @FindBy(css  = "div.form_control.ng-binding[title='Low'][ng-bind$='customerSegmentation']")
    WebElement Customer;
    
  • xpath:

    @FindBy(xpath = "//div[@class='form_control ng-binding' and @title='Low'][contains(@ng-bind, 'customerSegmentation')]")
    WebElement Customer;
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    working fine with me but after removing title as it change according to scenario thanks you alooot :) – M.Zaky Jul 21 '19 at 07:06