Element not visible, selenium - vba

I am trying to login to a site.
This is the problematic html part:
<input name="pass" id="vic_login_password" autocomplete="off" class="inpHM3_2" dir="ltr" type="password" value="" id="PasswprdH1" /><input type="text" value="Password" onfocus="this.style.display='none'; gid('vic_login_password').style.display='block'; gid('vic_login_password').focus();" class="inpHM3_3" />
My code:
driver.findElementById("vic_login_password").SendKeys "fakepass"
I get an error no -2146233088 saying that element is not visible.
For the user name everything works fine this way, but for the password I always get this error.

The key to solve the problem is inside that onfocus() event handler:
onfocus="this.style.display='none'; gid('vic_login_password').style.display='block'; gid('vic_login_password').focus();"
It is actually making one input invisible and the other one visible. The other one is the input with id="vic_login_password" which is initially invisible. This explains the error you've got.
In your code, you should first focus the visible input and only then send keys to the other one:
driver.findElementByCssSelector("input[value=Password][onfocus]").Click
driver.findElementById("vic_login_password").SendKeys "fakepass"

Related

WebPagetest not filling in forms, gives "Navigation Error"

I'm new to WebPagetest (https://www.webpagetest.org/) and am having some trouble with login forms. I am using scripting, and can navigate to the page with the form, but it appears as though I am not correctly entering any form values, nor is the form submitting.
Here is a version of my script:
logData 1
navigate https://www.example.com/secure/login
setValue name=username activation_test
setValue name=password password
submitForm id=signInForm
//clickAndWait id=signInBtn
//exec document.getElementsByTagName('html')[0].style.display = 'none';
sleep 5
block google.com/csi
navigate https://www.example.com/?jbhp=true
Of course, my first thought is to make sure that my HTML elements match, but they appear to be fine...
Username:
input tabindex="1" aria-required="true" class="success required" id="username" maxlength="64" name="username" placeholder="Email Address or Username" type="text" value=""
Password:
input tabindex="2" aria-required="true" class="success required" id="password" name="password" placeholder="Password" type="password" value=""
Form:
form action="#" id="signInForm" method="post" class="form formLarge" novalidate="novalidate"
Submit (verified within the form; only used when clickAndWait is uncommented):
button tabindex="3" id="signInBtn" class="ancBtn lrg" data-track-click="sign in : sign in" type="submit"
The result page of the test shows that it navigates to the final location as though not logged in. Also, I see this as part of the results: Step_2
(Error: Navigation Error). Sadly, if there is better documenting as to what specifically caused the navigation error, I have yet to find it.
Finally, if I switch from using "submitForm" to "clickAndWait" (which is commented out in the above example) the only difference in the result is that Step_2 shows a screenshot of the page rather than just an orange block.
IFrames. Stupid IFrames. If you find your way to my question, above, I would bet that your page has IFrames. In my case, my IFrame is coming from the same domain as the browser page -- if this is not the case for your IFrame, I'm not sure if this will work.
To access elements in the IFrame, I had to forget "setValue", "clickAndWait", and so on. I had to go straight to Javascript. Scripted, it looks something like these examples:
exec document.querySelector("iframe[id=stupidIFrameId]").contentDocument.querySelector("input[id=password]").value = 'password'
execAndWait document.querySelector("iframe[id=stupidIFrameId]").contentDocument.querySelector("button[id=signInButton]").click()

TestStack.Seleno TickCheckbox not working

I have 2 forms that I am testing using TestStack.Seleno. Both forms have a checkbox that is mandatory. The first form has (including the checkbox) 5 fields. I can use TestStack.Seleno to create a passing test with valid data. I set the checkbox like this:
Input.TickCheckbox(f=>f.Accept,form.Accept);
On my other form which has 10 or so fields, when I try to set the checkbox to be ticked (using the same code) nothing happens. However when I try
var acceptCheckBox = Find.Element(By.Name("Accept"),new TimeSpan(0,0,0,50));
if (form.Accept)
{
acceptCheckBox.Click();
}
I get error "Element is not currently visible and so may not be interacted with"
Element is clearly visible and is not injected in using javascript.
I am using latest version of TestStack.Seleno from github.
Any ideas?
So I have managed to figure out what the issue is and have a work around, however I cannot explain why it works on the other form. The mandatory Accept field has html generated by mvc that looks like
<div>
<input class="check-box" data-val="true" data-val-mustbetrue="The Accept our field is required" data-val-required="The Accept our field is required." id="Accept" name="Accept" type="checkbox" value="true"><input name="Accept" type="hidden" value="false">
<label for="Accept">
Accept our Please accept our Terms and Conditions
</label>
<span class="field-validation-valid" data-valmsg-for="Accept" data-valmsg-replace="true"></span>
</div>
So you have the checkbox and hidden field both with id Accept, I suspect in code seleno is picking up the hidden field and setting value, so I updated my code todo
var acceptCheckBox = Find.Element(By.CssSelector("#Accept.check-box"));
acceptCheckBox.Click();
Now everything works.
Ismail

Input hidden is built without value

Weird this one.
On my .NET MVC 4 project I've added a file on App_Code who contains this method:
#helper CheckBox(string name, bool isChecked = false, string className = "") {
<div class="checkboxHolder">
<input id="#name" name="#name" type="hidden" value="#isChecked") />
<i class="#className checkboxBts fa #((isChecked) ? "fa-check-square-o" : "fa-square-o")" data-checkbox-associated="#name"></i>
</div>
}
I'm using it to style checkboxes using font-awesome, so my app checkboxes are made of an input type hidden who stores a boolean value and an icon to give feedback to users.
Weird thing is, on executing when isChecked == false, the hidden returned by this method is like:
<input id="myCheckboxId" name="myCheckboxId" type="hidden" />
There is no value at all, when I try to save it to the model an exception is thrown saying that model cannot be saved.
I've fixed it changing the method to use:
<input id="#name" name="#name" type="hidden" #((isChecked) ? "value=true" : "value=false") />
Which is working fine. However, I wonder if anyone know what could be happening on the original output.
Thank you all.
It's not entirely a duplicate, but this is answered in Why is my hidden input writing: value=“value” instead of true/false?:
if you have:
<input name="somefield" type="hidden" someprop="#(SomeBooleanExpression)"/>
[and #SomeBooleanExpression] is false it is omitted completely:
<input name="somefield" type="hidden"/>
To get around this, consider .ToString()
So, use:
<input id="#name" name="#name" type="hidden" value="value="#(isChecked.ToString())" />

ModX Eform: Captcha not generating image

I am trying to get CAPTCHA working on the eForm plugin. I have added the input form field:
<label for="cfCaptcha">Captcha:<br />
<img src="[+verimageurl+]" alt="verification code"><br />
<input id="vericode" name="vericode" class="text" type="text">
and I have added
&vericode=`1`
to the eForm call.
and have added the Template Variable [+verimageurl+] to my template.
However, when I preview the form all I see in the image area is <img src="" alt="verification code">
Would anyone know what I am doing wrong?
Did you get this fixed?
Check that you ended the label code. Run it through w3c code checker too.
A few times I have left a element un-closed and it breaks the whole thing.

Selenium problem locating by DOM

I'm trying to use the DOM to locate a form element in Selenium but I can't get it to work. Even if I use the example in the Selenium documentation it still fails, for example with this html...
<html>
<body>
<form id="loginForm">
<input name="username" type="text" />
<input name="password" type="password" />
<input name="continue" type="submit" value="Login" />
<input name="continue" type="button" value="Clear" />
</form>
</body>
<html>
and this command in the Selenium IDE...
verifyElementPresent
with target...
dom=document.forms['loginForm']
I get [error] false in the log.
The 'getElementById' example in the documentation does work, but none of the others.
Can someone explain what I'm doing wrong here?
Thanks.
Not sure why it's not working (I can replicate the problem), but perhaps there's a better way to locate your target element? I would recommend locating by ID/name, falling back to CSS or XPath.
The format to locate a element is-
i) document.forms[index of the form].elements[index of the element]
index of the form = the index number (starting at 0) of the form with respect to the whole page, index of the element = the index number (starting at 0) of the element with respect to the whole form that contains it.
ii) document.forms[“name of the form”].elements[“name of the element”]
name of the form = the value of the name attribute of the form tag that contains the element you want to access, name of the element = the value of the name attribute of the element you wish to access
iii) document.getElementById(“id of the element”)
id of the element = this is the value of the ID attribute of the element to be accessed. This value should always be enclosed in a pair of parentheses (“”).
iv)document.getElementsByName(“name”)[index]
name = name of the element as defined by its ‘name’ attribute, index = an integer that indicates which element within getElementsByName’s array will be used.