Cannot select a button with Selenium IDE - selenium-ide

I am trying to test a web based application recording a test in Selenium IDE and have the following problem.
One of the fields (Title eg Mr, Mrs, etc.) requires the user to click a button that opens a new window with a List of Values.
When I click on the button IDE records it as css=button.BTNimgH and when playing back the script this error is displayed:
[error] Element css=button.BTNimgH not found
The code for the button is:
<button class="BTNimg" oldclassname="BTNimg" title="List of Values" tabindex="-1" onclick="disp_lov('STDCIF','BLK_CUSTPERSONAL','PCNTRY','Country','LOV_COUNTRY','','','', '', event)">
And the code for the filed I need the value in is:
<input id="BLK_CUSTPERSONAL__TITLE" class="TXTstd" type="text" viewmode="Y" onchange="disp_auto_lov('STDCIF','BLK_CUSTPERSONAL','TITLE','Title','LOV_TITLE','','','','', this, event);" label_value="Title" title="Title" dbt="BLK_CUSTPERSONAL" dbc="TITLE" name="TITLE" dtype="VARCHAR2" size="" required="" aria-required="false" maxlength="30" tabindex="0" prevautolovval="">
Any help would be greatly appreciated.

The problem might be the newly opened window not being selected. If you are going to interact to the elements in a new window, you need to use the selectWindow command.
Let me know if you have any more questions.

No Idea why it's doing it, but the locator has that extra H in it which will be causing the issue. Based on the code the locator should be
css=button.BTNimg

Related

Cannot locate button web element with xpath using selenium

In the website I want to automate the there is a button I want to click on, if you inspect the element of the button it looks like this:
<input type="submit" value="Login" class="submit">
So I click on this line any then do "Copy xpath" and copy it to my code like this:
val loginButton: WebElement = driver.findElement(By.xpath("""//*[#id="loginForm"]/fieldset/font/font/input """))
loginButton.click()
Its very weird cause in other places it worked perfectly and sometimes I have problems with it, and then I try by cssSelector but here nothing works :/
The path includes two layers of font elements which seems rather fragile to me - any slight changes to the page structure will mean this path fails to match.
I would try a path that considers just the "semantics" of which element you want to target, and not the precise structure of the page. You want the submit button in the login form, so how about a path like
//*[#id="loginForm"]//input[#type="submit"]
which finds any <input type="submit"> anywhere in the form. If there are several submit buttons you can be more specific with #type="submit" and #value="Login"
XPath is prone to break and IMHO overly complicated... I would use a CSS Selector.
driver.findElement(By.cssSelector("input.submit")).click();
This is Java, BTW, but hopefully you can translate it, if needed.

When we used ajax enabled Input fields inside template(build using p:layout)and p:tab, Need Double Click to Submit the form

I have some weird problem in my app.
I need to do the following and I achieved by using ajax events
1.add a tab dynamically ( using tab change event.when we click on + tab ,it will create new tab )
<p:ajax event="tabChange" listener="#{userBookBean.onBookTabChange}" update ="booksTabview"/>
2.remove a tab (using tab close event)
<p:ajax event="tabClose" listener="#{userBookBean.onBookTabClose}" update="booksTabview" />
3.Each tab have 5 input fields( Title, Author, Publisher, Rating (good, very good, excellent, must read), and Review )
all the input fields have its own ajax blur event call to submit its value.other wise all values are clear when switch the tab.
4.tab title can update by using one of the input field ( blur event )
<p:tab id="bookTab" title="#{book.title}">
<p:inputText value=#{book.title}">
<p:ajax event="blur" update="bookTab">
</p:inputText>
all above are working fine.
Except when I submit the form using commandButton,
After edit those fields.Need to click twice the button
first click send the ajax request with edited field value
second one submit the whole form.
<p:commandButton value="Submit" actionListener="#{bookBean.submit}" update=":booksform :breadcrumpform :successgrowl :errorgrowl :exceptionDialog" />
Is there any way to solve this problem? or what was wrong in my code?
When we click on Command Button,It will trigger the two following event
1.mousedown
2.mouseup
If we click the button after editing ajax enabled input fields,Ajax status model dialog will appear in between these events
so second one won't reach to server.
solution :
<p:commandButton value="save" onfocus="PF('statusDialog').hide();" actionListener="#{reportInfoBean.submit}"/>
Please suggest if you have any other way

XPages Typeahead autocomplete behavior

In XPages Mobile controls I'm having a problem with Typeahead. Actually I think the behavior changed recently - maybe with the last update of the Ext. Library but I'm not sure. Thats when we noticed the change by the way. Is has been working as desired.
Below are 2 screenshots. The first one is on a normal XPage and the second is inside Mobile Controls.
Notice how the user starts typing a "D" in the first one there's no "autocomplete". But in the second screenshot the user typed a "D" and it immediately added in the first value which in this case starts with an "O". It replaced the "D" that the user typed.
(The fact that the record with the beginning "O" is showing is working as designed, so ignore that.)
The problem is I don't want that autocomplete happening at all. I want the behavior of the first screenshot inside mobile controls. so the user can keep typing and it'll will continue to filter the list and not overwrite what the user entered.
I'm fairly certain it used to do that and I don't know what changed. The code itself did not change - that I know.
I've attempted to set autocomplete and autocorrect to "off" without any luck. I'm not sure what the difference is or if they even truly come into play.
How can I get the field to not auto-fill inside of Mobile Controls?
Any advice would be appreciated. I should note that this is privately going to be used on iPads. So it's the Mobile Safari browser.
Thanks!
Here is the basic code for this:
<xp:inputText id="inputJobCode" value="#{viewScope.selectedJob}"
styleClass="target span9">
<xp:this.attrs>
<xp:attr name="placeholder" value="Job Code" />
<xp:attr name="autocorrect" value="off" />
<xp:attr name="autocomplete" value="off" />
</xp:this.attrs>
<xp:this.dojoAttributes>
<xp:dojoAttribute name="autocorrect" value="off" />
<xp:dojoAttribute name="autocomplete" value="off" />
</xp:this.dojoAttributes>
<xp:typeAhead mode="partial" minChars="1" valueMarkup="true"
var="searchValue" valueList="#{javascript:return com.companyname.datahub.TypeAhead.jobTypeAhead(searchValue);}">
</xp:typeAhead>
<xp:eventHandler event="onchange" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:var key:String = viewScope.get("selectedJob");
getComponent("inputJobCode").setValue("");
//JobData.load(key);
}]]></xp:this.action>
</xp:eventHandler>
</xp:inputText>
Here is what the output HTML is from the mobile control page:
<input type="text" id="view:_id1:checkOutFacilityID_content:_id4:inputText5"
name="view:_id1:checkOutFacilityID_content:_id4:inputText5" autocomplete="off"
class="mblTextBox target" placeholder="Job Code" autocorrect="off"
dojotype="extlib.dijit.mobile.TypeAheadCombo"
store="view__id1_checkOutFacilityID_content__id4__id9" data-dojo-
props="list:'view__id1_checkOutFacilityID_content__id4__id9', searchAttr:'value',
labelAttr:'label', labelType:'html'" spellcheck="false" tabindex="0" lang="en"
widgetid="view:_id1:checkOutFacilityID_content:_id4:inputText5" value="">
I got an answer for this from the Maire at IBM.
There was a change made in a recent Ext. Library update regarding Type Ahead. The solution for now is to use dojo to add a setting. Here's the email that IBM sent me.
Hi David,
The mobile typeAhead behavior changed in the release 901v00_04.20140226-1506
For details of the changes, see the section "Improvements to XPages TypeAhead control support" in the readme.pdf for that release.
I'm reproducing the behavior you're talking about, and I've logged an SPR:
SPR#MKEE9L7E9BLink XPages, Mobile TypeAhead, first item in the dropdown is being inserted into the edit box (should not be)
To workaround the issue:
The workaround is to write a script changing the edit box behavior,
so insert this control into your XPage, and change the name inputText1 to match your edit box's name:
<xp:panel id="panel1">
<xp:eventHandler event="onClientLoad" submit="false">
<xp:this.script><![CDATA[dijit.byId('#{id:inputText1}').autoComplete=false;/*Note autoComplete=false is different to autocomplete=off*/ ]]></xp:this.script>
</xp:eventHandler>
</xp:panel>
Regards,
Maire
I note the dojoType added to mobile - dojotype="extlib.dijit.mobile.TypeAheadCombo". It sounds like that makes it a mixture of a combo box and typeahead, which explains the functionality you're seeing.
Does it work if you add that Dojo Attribute to the non-mobile one?

How can I prevent the Go button on iPad/iPhone from posting the form

I have a dynamic form that is to be displayed using an iPad.
This form has a couple of radio buttons and some text fields and one submit button.
In an iPad the virtual keyboard GO button is supposed to act ad the enter key, causing the first submit button in the form to be clicked and the form to be posted.
To avoid excessive involuntary postings before the form is complete we added an extra submit button higher up in the form, absolutely positioned outside of the visible area with onclick="return false;".
This hijacks the enter keystroke preventing accidental posting in every browser except Safari Mobile.
On an iPad we even tested Opera mobile and it works as expected.
But Safari Mobile apparently ignores the return false since event clicking the button causes a post that no other browser does, not even safari on PC.
My questions are
1: Why is safari mobile ignoring "return false" on submit, is there an other mechanism at play here?
2: How can I stop Safari mobile from posting the form when clicking GO?
I have made numerous searches on Google and Stackoverflow and found many examples but all requires a lot of javascript and event binding and the dynamic nature of the form along with user generated content makes this error prone and pretty complex since almost all required binding events to every textbox and textarea.
Any solution that works is good but the simpler the better, especially if it does not require to much customization of the form or events that might conflict with autocomplete or validation events.
Example testpage: http://lab.dnet.nu/ipad.php
I found a solution to my problem.
The base to the problem is that Safari mobile ignores onsubmit="return false" on buttons, it only works on forms.
Setting onsubmit="return false;" on the form, making a normal button (not submit) and setting onclick="form.submit()".
Ex.
<form method="post" onsubmit="return false;">
... //Other fields here
<input type="button" value="Send" onclick="form.submit();" />
</form>
The Go button does not trigger a normal button, only submit buttons.
Since the form has onsubmit="return false;" it will not post.
The button on the other hand, when clicked triggers the onclick="form.submit();" which overrides the onsubmit on the form.
This solution seems to work in any browser reliably.
Better answer is this. The other does not allow you to use a regular submit button. This attacks just the go button.
$("body").keydown(function(){
if(event.keyCode == 13) {
document.activeElement.blur();
return false;
}
});
Seems very unconventional, as this basically breaks general UX and expected device behaviour.
However, I think it also important to mention that this solution relies on the actual <form> DOM element. Meaning the onclick handler on the button should not use a jQuery object to submit but the DOM element.
jQuery object. Does not work:
<input type="button" value="Send" onclick="$("#myform").submit();" />
DOM element. Works:
<input type="button" value="Send" onclick="$("#myform").get(0).submit();" />
Without jQuery. Works:
<input type="button" value="Send" onclick="document.getElementById('myform').submit();" />
Also, here is a similar approach, using jQuery to intercept keyboard submits and only allowing clicks on a button. Credit goes to #levi: http://jsfiddle.net/RsKc7/
Here's an additional answer, in case anyone winds up chasing this issue like I did.
Provided you're using jQuery, the following snippet should prevent the "Go" button from triggering a form submission (at least it does on Nexus 7's Chrome on Android 4.2.2; YMMMV). Also, note that if you want to allow the "Enter" key to work on any of the input types below, this will prevent that from happening.
$(document.body).on('keydown', 'input:text, input[type=password], input[type=email]',
function (e) {
// Android maps the "Go" button to the Enter key => key code 13
if (e.keyCode == 13) {
return false;
}
});
Edit: It seems this bug breaks keyup/keydown in Chrome in Android > 4.3, in which case this fix will no longer work in some circumstances.
Cannot comment so i have to put a new message.
#David solution works fine if we are using an "input type button"; instead, if we are using a button tag doesn't seems to be solved by David fix.
(env: cordova, ipad mini 2)
Thanks David!
Go buttons and return buttons on mobile touch screen keyboards trigger the onclick event of your first submit button. To determine if its the user or script clicking the button, you can use the following:
$('#mybuttonId').onclick(e) {
if (e.screenX && e.screenX != 0 && e.screenY && e.screenY != 0) {
//This is the user clicking on the button.
} else {
//This is not the user, but a script , do nothing.
return false;
}
}

JSF2.0 PrimeFaces Navigation Problem

I have a problem with navigation too right now. I have 2 dataTables, one is located within a regular facelets-page, the other one is located in a dialog.
Both have the same code:
<p:commandButton
value="Show car"
ajax="false"
action="showCar?faces-redirect=true">
<f:setPropertyActionListener value="#{car}" target="#{carBean.car}" />
</p:commandButton>
I also tried adding process="#this" without success.
The problem is, while the navigation works for the commandButton inside the facelets-page, it doesnt work for the button inside the dialog. It seems that the current page is reloaded after the click.
Replacing it with a doesn't help either.
Has anybody experienced something like this before? Could this be an issue with the dialog?
Thanks and best regards,
Robert
Forget my previous answer, I didn't read your question carefully. What might be happening is a failure in your <f:setPropertyActionListener> call. If it is (silently) failing then the error will cause JSF to automatically navigate back to the same page.
Add this to your page somewhere so you can see any helpful error FacesMessages that may be provided by the framework:
<p:messages
id="messagesForDebugging"
showDetail="true"
autoUpdate="true" />
The autoUpdate will cause it flash up messages generated by global Ajax requests.
You may also want to put a logging statement in your carBean.setCar() method to make sure that it is successfully setting the value. If it is failing then maybe you need to provide a custom converter for Car values?