简体   繁体   中英

Selenium Python select input element

I try to enter a password to a TPlink router using Selenium. Which ID or Class I should select to fill a form?

Tried to below code but it crashed first line "pswd.click()" trying to access the element.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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