【发布时间】:2020-05-15 15:56:17
【问题描述】:
我正在尝试使用 Python Selenium 单击按钮。这是以下 HTML 结构:
<div id="auth_methods">
<fieldset data-device-index="phone1" class="">
<h2 class="medium-or-larger auth-method-header">
Choose an authentication method
</h2>
<div class="row-label push-label">
<input type="hidden" name="factor" value="Duo Push">
<span class="label factor-label">
<i class="icon-smartphone-check"></i>
Duo Push
<small class="recommended">
Recommended
</small>
</span>
<button class="positive auth-button" type="submit" tabindex="2"><!-- -->Send Me a Push</button>
</div>
<div class="row-label phone-label">
<input type="hidden" name="factor" value="Phone Call">
<span class="label factor-label">
<i class="icon-call-ringing" alt="" role="presentation"></i>
Call Me
</span>
<button class="positive auth-button" type="submit" tabindex="2"><!-- -->Call Me</button>
</div>
<div class="passcode-label row-label">
<input type="hidden" name="factor" value="Passcode">
<span class="label factor-label">
<i class="icon-smartphone-ellipsis" alt="" role="presentation"></i>
Passcode
</span>
<div class="passcode-input-wrapper">
<input type="text" name="passcode" autocomplete="off" data-index="phone1" class="hidden passcode-input"
placeholder="ex. 867539" aria-label="passcode" tabindex="2">
<div class="next-passcode-msg" role="alert" aria-live="polite"></div>
</div>
<button class="positive auth-button" type="submit" id="passcode" tabindex="2"><!-- -->Enter a Passcode
</button>
<input name="phone-smsable" type="hidden" value="True">
<input name="mobile-otpable" type="hidden" value="True">
<input name="next-passcode" type="hidden" value="None">
</div>
</fieldset>
<input type="hidden" name="has-token" value="false">
</div>
<button class="positive auth-button" type="submit" tabindex="2"><!-- -->Send Me a Push</button>
如何单击最底部的“向我发送推送”?我尝试使用 xpath 或类名。 例如,我做了:
driver.find_element_by_xpath('//*[@id="auth_methods"]/fieldset/div[1]/button').click()
我也做过:
element = driver.find_element_by_class_name('positive.auth-button')
但它告诉我无法找到元素。
【问题讨论】:
标签: python selenium button computer-science