【发布时间】:2022-01-28 00:07:49
【问题描述】:
我必须单击第一个 li 的 input type="button" 元素,但我不能引用 li 的 id,因为它每第二次打开网站,这是我尝试过的
driver.find_elements_by_xpath('//input[data-componentname="gender"]').get(0).click()
它给了我这个错误:
AttributeError: 'list' object has no attribute 'get'
如果我删除 get 部分,这是错误:
AttributeError: 'list' object has no attribute 'click'
这是代码,就像我说的,我必须单击第一个输入而不参考 id
<ul data-componentname="gender">
<li id="78ece221-1b64-4124-8483-80168f21805f" class="">
<input type="button">
<span>Uomo</span>
</li>
<li id="2678a655-b610-41e0-8e7f-bad58fbcb1b3" class="">
<input type="button">
<span>Donna</span>
</li>
</ul>
【问题讨论】: