Have a few issues clicking on a password field for my router web interface page. Below are 2 examples.
A: I get no errors, however the password field does not become show the password like when I manually click
B: I get a element not clickable or with a slight change element not interactable
My question is what am I missing here. Below is the elements from the page
<div class="controls">
<input type="password" id="wrlPwd" name="wrlPwd" class="validatebox input-large" maxlength="63" data-options="{"type":"ssidPwd","args":[8,63]}">
</div>
And below the 2 parts of code
A: PsWrD = browser.find_element_by_class_name('control-label')
B: PsWrD = browser.find_element_by_xpath('//div[@id="id="wrlPwd"" and @class="controls"]') browser.execute_script("arguments[0].click();", PsWrD)
The goal is not to view the password but highlight the text field to change the password. I attempted a few other things such as css and name. I am able to navigate every where else but I am stuck on this little bit.
CodePudding user response:
The element you are trying to click is
<input type="password" id="wrlPwd" name="wrlPwd" class="validatebox input-large" ...>
Always start with ID or name, if they are available. This one has both so lets use ID
browser.find_element_by_id("wrlPwd").click()
The locators you are using are not correct.
A: There is no class, control-label
, on the INPUT element you posted. The class is class="validatebox input-large"
and the classes are validatebox
and input-large
.
B: Same problem with this one... you are confusing elements or something. The XPath you are using, //div[@id="id="wrlPwd"" and @class="controls"]
has a couple issues.
- You've mangled the id in there twice,
@id="id="wrlPwd""
, which should have thrown an invalid XPath error, and the DIV does not have that ID, the INPUT does. - The second part,
and @class="controls"
, is correct for the DIV but you want to click the INPUT.
Additionally, you may want to add a WebDriverWait
to wait for the INPUT to be clickable if there are timing issues. See the docs for more info.
CodePudding user response:
The issue here was my HTML Knowledge. The issue was my element was in an iframe and so could not find it. To resolve I used:
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"membeeLoginIF")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.textboxWaterMark#txtUserName"))).send_keys("Jeff")```
Once I switched to the iframe i found it with out issue