简体   繁体   English

Selenium Python select 输入元件

[英]Selenium Python select input element

I try to enter a password to a TPlink router using Selenium.我尝试使用 Selenium 输入 TPlink 路由器的密码。 Which ID or Class I should select to fill a form?哪个ID或Class我应该select填写表格?

Tried to below code but it crashed first line "pswd.click()" trying to access the element.尝试使用下面的代码,但它在尝试访问该元素时崩溃了第一行“pswd.click()”。

ID="login-password"
pswd = driver.find_element(By.ID, ID)
pswd.click()                    # Click to active
pswd.clear()                    # Clear data
pswd.send_keys(password)        # Fill password
pswd.send_keys(Keys.RETURN)     # press <RETURN>


<div class="login-field">
<label id="login-password-label">
<span class="icon"></span>
<span class="text"></span>
</label>
<div class="container widget-container text-container password-container inline-block login-text error">
<div class="widget-wrap-outer text-wrap-outer password-wrap-outer">
<div class="widget-wrap text-wrap password-wrap allow-visible">
<span class="text-wrap-before">
</span>
<span class="text-wrap password-wrap ">
<input type="password" class="text-text password-text password-hidden l" maxlength="16">
<input type="text" class="text-text password-text password-visible hidden l" maxlength="16">
<span class="icon allow-visible-btn"></span>
<input id="login-password" name="password" type="password" class="hidden">
</span><span class="hint text-hint password-hint">
<input class="text-hint password-hint l" value="Password" contenteditable="false" readonly="readonly" style="display: none;">
</span>
<span class="text-wrap-after">
</span>
</div>
<div class="widget-tips textbox-tips m">
<div class="content tips-content" style="display: none;">
</div>
</div>
<div class="widget-error-tips textbox-error-tips show" style="height: 24px;">
<span class="widget-error-tips-delta">
</span>
<div class="widget-error-tips-wrap show" style="display: block; left: 0px; top: 0px;">
<div class="content error-tips-content">
</div></div></div></div></div>
<a class="link inline-block" href="javascript:void(0);" id="btn-forget-password">Forgot password?</a> 
</div>

tha is a hidden element, you should operate on this element: <input type="password" class="text-text password-text password-hidden l" maxlength="16"> , you can try find_elements_by_class_name() tha 是隐藏元素,你应该对这个元素进行操作: <input type="password" class="text-text password-text password-hidden l" maxlength="16"> ,你可以试试 find_elements_by_class_name()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM