gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 02:21:45 25 4
gpt4 key购买 nike

我是第一次使用 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>

复选框

<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

您可以选择列表、单选按钮、span 等等,只需学习 Xpath 就值得付出努力。

关于python - selenium 是否写入和读取 webelement 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14202609/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com