dimanche 28 janvier 2018

Selenium Webdriver - How to select checkbox, if it has no id?

So i have this Google Docs survey and there are Checkboxes which i want to check with Selenium Webdriver automatically.

I as usually tried to locate the element id oder the name of it via the editor mode on google chrome, but i simple do not find the id of the checkbox, only the corresponding class name.

<label class="docssharedWizToggleLabeledContainer 
freebirdFormviewerViewItemsRadioChoice"><div class="exportLabelWrapper"><div 
class="quantumWizTogglePaperradioEl docssharedWizToggleLabeledControl 
freebirdThemedRadio freebirdThemedRadioDarkerDisabled 
freebirdFormviewerViewItemsRadioControl" jscontroller="EcW08c" 
jsaction="click:cOuCgd; mousedown:UX7yZ; mouseup:lbsD7e; mouseleave:JywGue; 
touchstart:p6p2H; touchmove:FwuNnf; 
touchend:yfqBxc(preventMouseEvents=true|preventDefault=true); 
touchcancel:JMtRjd; focus:AHmuwe; blur:O22p3e; keydown:I481le; 
contextmenu:mg9Pef" jsshadow="" aria-label="Männlich" tabindex="0" data-
value="Männlich" aria-describedby="  i5" role="radio" aria-checked="false" 
aria-posinset="1" aria-setsize="3"><div class="quantumWizTogglePaperradioInk 
exportInk"></div><div class="quantumWizTogglePaperradioInnerBox"></div><div 
class="quantumWizTogglePaperradioRadioContainer"><div 
class="quantumWizTogglePaperradioOffRadio exportOuterCircle"><div 
class="quantumWizTogglePaperradioOnRadio exportInnerCircle"></div></div>
</div></div><div class="docssharedWizToggleLabeledContent"><div 
class="docssharedWizToggleLabeledPrimaryText"><span dir="auto" 
class="docssharedWizToggleLabeledLabelText exportLabel 
freebirdFormviewerViewItemsRadioLabel">Männlich</span></div></div></div>
</label>
<div class="quantumWizTogglePaperradioRadioContainer"><div 
class="quantumWizTogglePaperradioOffRadio exportOuterCircle"><div 
class="quantumWizTogglePaperradioOnRadio exportInnerCircle"></div></div>
</div>

"Männlich" is here just the text of a label which belongs to the checkbox i want to mark, but not the checkbox as an element by itself.

I hope some of you have some suggestions how to implement the method

driver.findElement(By.name("name"))
driver.findElement(By.id("id"))

in this case. Or should i try something else?

Thanks already for everyone thinking about an awnser!




Aucun commentaire:

Enregistrer un commentaire