There are two fields in the page: Username and Password(Highlighted in the below code with **). Need to enter data into it using selenium. However, both the objects have same identifier elements except tabIndex. Please help me as to How to identify the elements(Please refer html).
Please note: The below code worked for me but user will not be able to see the data that is input in the GUI. I want the data to be seen on the UI.
Thanks,
Mike
@FindBy(name="cams_cb_username")
private WebElement emailId;
@FindBy(name="cams_cb_password")
private WebElement password;
((JavascriptExecutor)DriverFactory.getDriver()).executeScript("arguments[0].setAttribute('value',arguments[1]);", emailId, "username");
((JavascriptExecutor)DriverFactory.getDriver()).executeScript("arguments[0].setAttribute('value',arguments[1]);", password, "pwd");
Here is the HTML.
<form action="/vito-mma/activateLogin.do" method="post" name="loginForm">
<input type="hidden" value="vitocom" name="cams_security_domain">
<input type="hidden" value="/vito-mma/showPlans.do" name="cams_original_url">
<input type="hidden" value="http" name="cams_login_config">
<input type="hidden" value="" name="cams_cb_partner">
<fieldset class="mma-signin">
<div class="clearfix">
<**input class="bigtext e-hint" type="text" value="" name="e_hint_dummy_input" size="25" autocomplete="off" tabindex="1" style="display: inline;"**>
<input class="bigtext e-hint" type="text" title="Email address" value="" tabindex="1" size="25" name="cams_cb_username" style="display: none; background-color: rgb(255, 255, 255);" autocomplete="off">
</div>
<div class="clearfix">
<**input class="bigtext e-hint" type="text" value="" name="e_hint_dummy_input" size="25" autocomplete="off" tabindex="2"**>
<input class="bigtext e-hint" type="password" title="Password" value="" tabindex="2" size="25" name="cams_cb_password" style="display: none; background-color: rgb(255, 255, 255);" autocomplete="off">
</div>
</fieldset>
<div class="indent">
</form>
Note:
Tried with Xpath: Did not work.
Recorded with IDE for username, (name=”cams_cb_username”). Used this – Did not work either.
You could customize the xpath to use the
tabindexattribute and thenameattribute :Or alternatively, you could use something like this :
Hope this helps.