Selenium writes and reads webelement values

I am doing automation using Python2.7 and selenium for the first time. Now can I write and read also the content below HTML?

Radio buttons

<form name="myWebForm" action="mailto: youremail@email.com " method="post"> <h4>Please select your favorite food category.</h4> <input type="radio" name="food" /> : Italian<br /> <input type="radio" name="food" /> : Greek<br /> <input type="radio" name="food" /> : Chinese<br /> <h4>Please select your gender.</h4> <input type="radio" name="gender" /> : Male<br /> <input type="radio" name="gender" /> : Female<br /> </form> 

Single pick list

  <select size="3" name="selectionField" multiple="yes" > <option value="CA" >California -- CA </option> <option value="CO" >Colorado -- CO</option> <option value="CN" >Connecticut -- CN</option> </select> 

Protection list

 <dl> <dt>Coffee</dt> <dd>- black hot drink</dd> <dt>Milk</dt> <dd>- white cold drink</dd> </dl> 

Checkboxes

 <form name="myWebForm" action="mailto: youremail@email.com " method="post"> <p>Please select every sport that you play.</p> Soccer: <input type="checkbox" name="sports" value="soccer" /><br /> Football: <input type="checkbox" name="sports" value="football" /><br /> Baseball: <input type="checkbox" name="sports" value="baseball" /><br /> Basketball: <input type="checkbox" name="sports" value="basketball" /> </form> 
+4
source share
1 answer

Yes, check in xpath

 x = brower.select_element_by_xpath('//option[contains(text(), "CO"]') x.text (print the div text) x.click() clicks the div 

or simply

 brower.select_element_by_xpath('//option[contains(text(), "CO"]').click() 

to read the list, this should work;

 for i in browers.select_elements_by_xpath('//select[@name="selectionField"]//option'): print i.text 

you can select a list, radio buttons, cover everything, just explore the Xpath, which is worth the effort.

+7
source

All Articles