0
votes

As showing in the picture below

enter image description here

I am not able to click in a element which has div class and text

i have tried using contains text and preceding.

private IWebElement Claimcontact_Insured_No => 
   FindElement(By.XPath("//div[contains(text(),'No')]/preceding::div[@class='mat-button-toggle-label-content']"));

I get the result: Unable to find the element

1
source code : <div class="mat-button-toggle-label-content"> No </div> - rai
Please add the whole html corresponding to the element. - Sameer Arora
<label class="mat-button-toggle-label" for="mat-button-toggle-2-input"> <input class="mat-button-toggle-input cdk-visually-hidden" type="radio" id="mat-button-toggle-2-input" name="unAuthContactSameAsInsured"> <div class="mat-button-toggle-label-content"> No </div> </label> @SameerArora - rai
Can you check that is there any iframe present anywhere in the html of the element ? - Sameer Arora
No iframe. I am able to click the element with div class . have a look at the image.@SameerArora - rai

1 Answers

0
votes

As discussed, there is no iframe present in the html structure.
So, try the below xpath for clicking on the No button:

FindElement(By.XPath("(//div[@class='mat-button-toggle-label-content'])[2]"));

Updating the answer after checking the html of the website and the element.
The element does have the id as well which is unique, so instead of using the xpath, id should be used like:

FindElement(By.ID("mat-button-toggle-2"));