I am doing automation using Python2.7 and selenium first time. Now can I write and read as well the below HTML contents?
Radio Buttons
<form name="myWebForm" action="mailto:[email protected]" 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 Select 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>
Defination 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:[email protected]" 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>
Each WebElement is represented in Selenium via the WebElement interface – which is used by Selenium to interact with visible and invisible elements on the web page. This command returns either the element being searched for or returns null/void.
The Selenium WebDriver interface has predefined the getText() method, which helps retrieve the text for a specific web element. This method gets the visible, inner text (which is not hidden by CSS) of the web-element.
The getAttribute() method helps to get the value of any attribute of a web element, which is returned as a String. If an attribute has a Boolean value, the method returns either True or null. Also, if there is no attribute, the method will return null.
Yes, check into xpath
x = brower.select_element_by_xpath('//option[contains(text(), "CO"]')
x.text (print the div text)
x.click() clicks the div
or just
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 list, radio buttons, span's whatever, just learn Xpath it's worth the effort.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With