微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

python – selenium是否写入和读取webelement值

我第一次使用Python2.7和selenium进行自动化.我现在可以编写和阅读下面的HTML内容吗?

单选按钮

<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>

单选列表

  <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>

定义清单

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

的CheckBox

<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>

解决方法:

是的,请检查xpath

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

要不就

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

阅读清单,这应该工作;

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

你可以选择列表,单选按钮,跨度等等,只需学习Xpath值得付出努力.

原文地址:https://codeday.me/bug/20190613/1230590.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐