简体   繁体   中英

How I can click a disclaimer checkbox using selenium java from a survey page

How I can click a disclaimer checkbox using selenium java from a survey page. I tried with CSS selector or XPath, but I think that I don't know how to compose that necessary selector correctly.

What I tried:

 @FindBy(xpath = ".disclaimer input[type='checkbox']")
    WebElement disclaimer;

Or

  @FindBy(xpath = "//input[@name='select-14'] [type='checkbox']")
    WebElement disclaimer;

Many attempts, I do not have all the combinations tried

The disclaimer code is:

    <div class="questions normal question-14">
<div style="">
<strong class="title">11. Ati avut recent modificari in tranzitul intestinal sau in activitatea vezicii urinare?</strong> 
<p class="description">Ex: incontinenta sau incapacitatea de a urina</p> 
<div class="question">
<strong class="title">Ati avut recent modificari in tranzitul intestinal sau in activitatea vezicii urinare?</strong> 
<div class="answers"><label class="selected"><img class="icon" style="display: none;"> <
input type="radio" name="select-14" value="0">    Da   </label></div>
<div class="answers"><label><img class="icon" style="display: none;"> <input type="radio" name="select-14" value="1">    Nu   </label></div> </div> 
<div class="disclaimer" style=""><label><input type="checkbox" id="disclaimer"> Inteleg ca evaluarea/ opinia/ informatiile furnizate nu reprezinta un diagnostic exact sau un sfat medical si acestea nu pot substitui consultul si tratamentul prescris de catre medicul specialist. Aceasta autoevaluare este exclusiv cu titlu informativ, iar pentru stabilirea unui diagnostic, este recomandat sa efectuati un consult la medicul specialist. Rezultatul acestui formular are ca scop evaluarea preliminara a cauzei durerilor cu care ma confrunt.</label>
 <p>Completarea acestui formular nu are drept scop stabilirea unui diagnostic asociat coloanei vertebrale. Utilizarea rezultatului evaluarii sau a oricarei informatii primite dupa completarea acestui Formular se va face exclusiv pe raspunderea mea.</p></div>
 <div classname="clearfix"></div> <div class="actions"><a id="prev" class="btn gray" style="">   Inapoi  </a> 
<a id="next" class="btn isDisabled" style="">   Continua  </a></div></div></div>
    <input type="checkbox" id="disclaimer">

The problem is that the questionnaire has 11 questions and in HTML behind this question is this disclaimer

If you can recommend me some tutorials for composing the tenants? I am easy to identify by name, title, etc. but for more advanced things I get stuck. Or can someone explain to me how they are composed, these tenants inherit

If the question is not clear, you can tell me what to change and I will adapt, I am at the beginning with stackoverflow

It's really unclear what disclaimer checkbox are you talking about.
The page contains multiple disclaimer element but most of them are hidden.
I saw it only after I filled all the survey steps, before final submitting the survey data.
I this is the element you asking for try this XPath:
"//div[contains(@class,'question-14')]//input[@id='disclaimer']"
In case we know the disclaimer we are looking for is inside the 14-th question the XPath expression is built as above: you find the 14-th question block and what is //div[contains(@class,'question-14')] coming for and now we are looking for disclaimer input inside it so why the //input[@id='disclaimer'] is coming after it meaning //input[@id='disclaimer'] inside the //div[contains(@class,'question-14')] element

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM