Error occured when Click on an Anchor using HtmlUnit - htmlunit

Using HtmlUnit i can get this Image element for a webpage
<pre> <a onclick="return OnSubmitValidateSignUp();return ValidEmail();" id="lnkSave" tabindex="10" class="create" href="javascript:__doPostBack('lnkSave','')"></a> </pre>
using
<i> HtmlAnchor button = (HtmlAnchor) currentPage.getByXPath("//* [#id=\"lnkSave\"]").get(0);
System.out.println(" anchor "+ button.getId());</i>
But when i put button.click(); following error occured.
Sep 28, 2012 6:39:59 PM com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
WARNING: Obsolete content type encountered: 'application/x-javascript'.
Exception in thread "JS executor for com.gargoylesoftware.htmlunit.WebClient#f27a6e" java.lang.OutOfMemoryError: Java heap space
at java.util.Hashtable.put(Hashtable.java:458)
at java.util.Properties.load0(Properties.java:392)
at java.util.Properties.load(Properties.java:341)
at java.util.PropertyResourceBundle.<init>(PropertyResourceBundle.java:130)
at java.util.ResourceBundle$Control.newBundle(ResourceBundle.java:2610)
at java.util.ResourceBundle.loadBundle(ResourceBundle.java:1436)
at java.util.ResourceBundle.findBundle(ResourceBundle.java:1400)
at java.util.ResourceBundle.findBundle(ResourceBundle.java:1354)
at java.util.ResourceBundle.findBundle(ResourceBundle.java:1354)
How can i solve this problem?

this is a javascript issue. It seems you have some javascript attached to the OnClick event of the button. First try is to disable JS, if possible. Second try take a look at this answer: HtmlUnit is throwing Out Of Memory and maybe leaking memory, it might help.

Related

How do you insert text/value in google doc using Watir/ruby

The google doc is embedded on a website inside an iframe.
Here is the code I use to try to insert a random text on the google doc
sample_text = Faker::Lorem.sentence
$browser.iframe(id: 'google_iframe').div(xpath: "//div[#class='kix-lineview']//div[contains(#class, 'kix-lineview-content')]").send_keys (sample_text)
$advanced_text_info['google_doc_article'] = sample_text
But im getting error when I run the test
element located, but timed out after 30 seconds, waiting for #<Watir::Div: located: true; {:id=>"google_iframe", :tag_name=>"iframe"} --> {:xpath=>"//div[#class='kix-lineview']//div[contains(#class, 'kix-lineview-content')]", :tag_name=>"div"}> to be present (Watir::Exception::UnknownObjectException)
Problem
The root of the problem is how Google Docs has implemented their application. The div you are writing to does not include the contenteditable attribute:
<div class="kix-lineview-content" style="margin-left: 0px; padding-top: 0px; top: -1px;">
As a result, Selenium does not consider this element in an interactable state. A Selenium::WebDriver::Error::ElementNotInteractableError exception is raised. You can see this by bypassing Watir and calling Selenium directly:
browser.div(class: 'kix-lineview-content').wd.send_keys('text')
#=> Selenium::WebDriver::Error::ElementNotInteractableError (element not interactable)
Watir confuses the matter by hiding the exception. As seen in the following code, the not interactable error is raised as an element not present exception - UnknownObjectException. I am not sure if this was intentional (eg backwards compatibility) or an oversight.
rescue Selenium::WebDriver::Error::ElementNotInteractableError
raise_present unless browser.timer.remaining_time.positive?
raise_present unless %i[wait_for_present wait_for_enabled wait_for_writable].include?(precondition)
retry
In summary, the problem is that the element is not considered interactable rather than because it isn't present.
Solution
I think the best approach here is to make the div interactable before trying to set the text. You can do this by adding the contenteditable attribute yourself:
content = browser.div(class: 'kix-lineview-content') # This was sufficient when using Google Docs directly - update this for your specific iframe
content.execute_script('arguments[0].setAttribute("contenteditable", "true")', content)
content.send_keys(sample_text)

Robot Framework: Issue in checking for a text after span

In Robot Framework, I am trying to check whether "XXX" exists in the source code as follows:
<button class='btn-aaa'>
<span class='bbb'>
XXX
</button>
I tried with the following codes but they failed:
Page Should Contain Element | //button/span/following-sibling::text()="XXX"
---> Valid xpath but encountering error in Robot Framework with error message "InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //button/span/following-sibling::text()="XXX" because of the following error: TypeError: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type."
Page Should Contain Element | //button/span[#class='bbb']/following-sibling::contains(text(),"XXX")
---> Invalid xpath
Page Should Contain Element | //button/span[#class='bbb']/following-sibling::[contains(text(),"XXX")]
---> Invalid xpath
Could anyone please suggest the proper way to check for "XXX" using the right xpath in Robot Framework?
The following are the info of the tools utilised:
robot framework version 3.0.4
Selenium Version 3.14.1
Selenium2Library Version 3.0.0
Python 3.6.6
Edited:
I really appreciate that all of you are trying to help. Thank you very much.
I will try to provide as much info as I can, so that you can help me as well.
I tried with:
//button[normalize-space()='View Data']
Unfortunately, it found nothing.
There are other buttons but there is only one with the text "View Data".
Here are more detailed code. I don't know whether it will help comparing with the simplified one mentioned earlier:
<button class="btn btn-submit float-left" type="button" onclick="return doActionParam('https://www.blabla.com/blabla',{op:'viewBla',blaId:'wxyz', activeTab:getActiveTabName()})">
<!--groupParent.-->
<span class="bongobongo"></span>
View Data
<button>
Hope the info is more helpful this time. Thanks again.
Additional Info:
Browser: Mozilla Firefox 62.0.3 (64 bits)
Could you try this xpath: //button[normalize-space()='XXX']
Your test should be: Page Should Contain Element //button[normalize-space()='XXX']
The problem is that your page does not contain a span with the text "XXX". What it actually has is "newline, XXX, newline". Also, neither the span nor the button has a sibling (and thus, no following-sibling).
You can ignore the whitespace surrounding the text with normalize-space. For example, the following works for me when I create an HTML document identical to what you have in your question:
Page should contain element //button[normalize-space()='XXX']
This should work on the updated example in your code, by simply replacing XXX with View Data:
Page should contain element //button[normalize-space()='View Data']

jQuery Mobile 1.4.2 Click Event Not Firing After DOM Manipulation & Page Refresh

I am trying to use single page mobile site. Basically I have a listview inside container and click event for list class.
<div role="main" class="ui-content">
<ul data-role="listview" data-inset="true">
<li class="listbtn">
</li>
</ul><!-- /listview -->
</div><!-- /content -->
I have a script for firing "listbtn" click event
$(".listbrn").click(function(){
});
this is working fine when page loads for first time
On another event, I am pulling data and replacing the whole "listview" with new items.
After DOM manipulation is successful, I have used
$('.ui-page-active .ui-listview').listview('refresh');
$.mobile.activePage.trigger('create');
as suggested on other threads.
Up to this point everything is smooth, page refreshes with new items and CSS applied nicely as expected.
Only problem is "listbtn" click event is not firing after that.
While looking for answers, I found this thread and tried to use live as suggested but after changing to live page won't load at all. Loading gif images spins forever.
Any suggestion or ideas?
jQuery 2.0
jQM 1.4.2
Thanks
You need to delegate event to dynamically added elements.
Another note, you don't need $.mobile.activePage.trigger('create');, .listview("refresh") is enough to re-enhance list-view. Not to mention that both $.mobile.activePage as well as .trigger('create') are deprecated and will be removed on jQM 1.5.
$(document).on("click", ".listbtn", function () {
/* code */
});
Demo

FullAjaxExceptionHandler does not redirect to error page for Ajax request

I know there has been numerous questions here on this question, but almost all of them suggest adding the following code because there is another layer "above" the FullAjaxExceptionHandler that is sending a plain redirect instead of doing an Ajax redirect (see this similar question):
if ("partial/ajax".equals(request.getHeader("Faces-Request"))) {
// JSF ajax request. Return special XML response which instructs JavaScript that it should in turn perform a redirect.
response.setContentType("text/xml");
response.getWriter()
.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
.printf("<partial-response><redirect url=\"%s\"></redirect></partial-response>", loginURL);
} else {
// Normal request. Perform redirect as usual.
response.sendRedirect(loginURL);
}
My question is that I'm simply configuring Omnifaces's FullAjaxExceptionHandler to do all the error handling, I do not have Spring Security or container managed security that is intercepting the request before FullAjaxExceptionHandler can do it's thing. I can breakpoint into FullAjaxExceptionHandler and see that when the following lines of code is executed, my error page is still not being redirected.
String viewId = Faces.normalizeViewId(errorPageLocation);
ViewHandler viewHandler = context.getApplication().getViewHandler();
UIViewRoot viewRoot = viewHandler.createView(context, viewId);
context.setViewRoot(viewRoot);
context.getPartialViewContext().setRenderAll(true);
...
context.renderResponse();
Instead, the Ajax request where the exception originated has this in it's response body:
<?xml version='1.0' encoding='UTF-8'?>
<partial-response>
<changes>
<update id="javax.faces.ViewRoot"><![CDATA[<html xmlns="http://www.w3.org/1999/xhtml">... html of error page here ... </html>]]></update>
<update id="javax.faces.ViewState"><![CDATA[-3527653129719750158:5595502883804776498]]></update>
</changes>
</partial-response>
It looks like FullAjaxExceptionHandler isn't doing what it's supposed to do, or am I missing something?
Update
Attaching browser JS output console screen cap.
Problem Identified
Turns out that the HTML of my error page is malformed, it contains the following snippet, which results in the mismatched tag error in the browser:
<script type="text/javascript">
//<![CDATA[
scrollTo(0, 0);
//]]>
</script>
This seemed to have closed the CDATA tag prematurely. This HTML was a result of the <h:outputScript/> tag, which I removed since I don't really need it.
Many years after the original question, now using Wildfly 15, JSF 2.3, OmniFaces 3.2, I stumbled upon a similar issue: Malformed partial response from the FullAjaxExceptionHandler in case of an exception during an ajax call. The cause was a nested CDATA in the response, thus commenting out a part of the response, resulting in a XML parse error. The culprit appeared to be the JSF tag ui:debug. I have removed the statement and now it works as intended.
The ajax response looks completely fine, it's having an <update id="javax.faces.ViewRoot"> containing the whole error page document, so the FullAjaxExceptionHandler did its job properly.
Your concrete problem is more likely caused in the client side or even in the error page document itself, after the ajax response has been retrieved. It's then JavaScript's turn to parse that ajax response and replace the current HTML document accordingly. Checking the browser's JavaScript console should give any clues as to problems during that step. In your particular case, the problem seems to be caused by a nested CDATA block around the content rendered by <h:outputScript> which in turn caused a JavaScript parsing error.
Unfortunately, I can't reproduce the problem with any Mojarra version I've at hands. Perhaps you've somewhere a custom/3rd party script renderer who's responsible for adding that CDATA block. That script renderer should skip the CDATA block when PartialViewContext#isAjaxRequest() returns true. If you still can't figure it out, then your best bet is to replace the <h:outputScript> by a plain HTML <script> or even to remove it altogether — as you ultimately did.

Watin - Cannot find link element (Javascript)

I'm using watin to automate a process on a web system (internal).
I can open the website and access some links, but others cannot be found. I think this may be either because they are deeply nested or because the href is javascript. This is the format they are in:
<frame>
<html>
<frameset>
<frame>
<html>
<body>
<div>
<table>
<table>
<tr>
<td>
<a id="1_1_1_a" href="javascript:blah" </a>
I've tried various different ways to find by id, element type etc. But I'm stuck on this.
Can anyone help?
Thanks
Elements within a frame have to be searched through its frame because each frame is considered a separate namespace in WatIn. So first get the correct frame (by calling the Frame method or through the Frames property - note that in your example you must do it twice as you have two nested frames) and then search for the link, e.g.:
ie.Frames[0].Frames[0].Link("1_1_1_a")
Try this
using (var browser = new IE("your_web_site_here"))
{
try
{
Frame first_frame = browser.Frame(Find.ById("frame_1_id"));
Frame second_frame = first_frame.Frame(Find.ById("frame_2_id"));
var first_div = second_frame.Div(Find.ById("first_div_id"));
Assert.IsTrue(first_div.Exists);
var Link_to_click = first_div.Link(Find.ById("1_1_1_a"));
Assert.IsTrue(Link_to_click.Exists);
Link_to_click.Click();
}
catch (Exception ex)
{
}
}
Sometimes watin cannot find elements I'm still trying to find out why and what are the preconditions.
I had a similar issue where my test would browse to a page that had 40 links on it and even though you could see all the links on the page the following statement would show links (and other elements collections) had a count of zero.
ie.Links.Count();
I'm still not sure exactly what the underlying issue is but I discovered that if you start Gallio Icarus / Gallio Echo / Visual Studio (or whatever test runner you are using) by Right Click -> Run as administrator the test works as expected and the elements are loaded into the ie browser object correctly.

Resources