phantomjs is not honoring page break, I tried couple of things
p1
<p><!-- pagebreak --></p>
p2
<p style="page-break-after:always;"></p>
p3
But they did not work, do you know any trick to force phantomjs to break the page ?
Related
I'm having difficulty testing a piece of code using NightwatchJS with Selenium and SafariDriver.
I have an open issue for this on nightwatch repo, although am not sure if it is an issue with nightwatch or something deeper.
The HTML content to be tested looks something like:
<body>
<iframe id="top-iframe" src="about:blank">
#document
<html>
<body>
<container>
<!-- access this iframe to test -->
<iframe id="nested-iframe" src="news.google.com"></iframe>
</container>
</body>
</html>
</iframe>
</body>
Where #nested-frame will need to be accessed from the top level document for inspection of content.
The test code is using NightwatchJS, more details about config, setup and code are in the GitHub issue.
The Gist of the issue:
The problem is that to access the nested iFrame, it needs to first find #top-frame web element, use the returned web element and pass it to frame which makes the WebDriver call to change context of test session to that frame. This is all good with Chrome, FF, and Safari as they can all find this frame web element and make the switch into the frame context. My test that Safari was changing iFrame context, although not sure how good it is, was to try and find another DOM element other than the nested frame, which it could find. The problem comes when with Safari, after switching into #top-frame, it cannot find the #nested-frame web element, and Nightwatch returns a 404 no such element from the HTTP call. Strange, right?
It is very puzzling, my latest thinking was maybe it was a cross origin issue. But then I read on WebDriver switch to frame:
NOTE WebDriver is not bound by the same origin policy, so it is always possible to switch into child browsing contexts, even if they are different origin to the current browsing context.
And I also tried checking Disable Cross Origin Restrictions from Safari Developer menu.
As mentioned before, I can find another DOM element in the #top-frame. I tried things like 10-15s timeouts thinking maybe it needed to load. I can inspect the browser with debugger and see that #nested-frame is there and the content loads as expected. There are not console errors indicating any content failed to load.
It's very puzzling to me and I'm not sure how to further debug. Maybe someone else with a fresh perspective could have a suggestion or if someone has run into a similar situation as this. Throwing this out into the universe as information is limited on the topic too, so maybe this could help someone else. TIA!
iframes
As per the documentation iframe is a construct which embeds a document into an HTML document so that embedded data is displayed inside a subwindow of the browser's window. This does not mean full inclusion and the two documents are independent, and both them are treated as complete documents, instead of treating one as part of the other.
iframe structure and details
Generally, an iframe element is in the form of:
<iframe src="URL" more attributes>
alternative content for browsers which do not
support iframe
</iframe>
Browsers which support iframe display the document referred to by the URL in a subwindow, typically with vertical and/or horizontal scroll bars. Such browsers ignore the content of the iframe element (i.e. everything between the start tag <iframe...> and the end tag </iframe>). Browsers which do not support iframe (or have such support disabled) does the opposite, i.e. process the content as if the <iframe...> and </iframe> tags were not there. Thus, the content matters, despite being ignored by some browsers.
This usecase
As the top-level <iframe> is having src="about:blank" it is highly unlikely there can be any child <iframe>. Hence, in absence of any child <iframe> your attempt to access any nested <iframe> will fail.
Reference
You can find a relevant detailed discussion in:
Ways to deal with #document under iframe
After discussion with Selenium team, this appears to be a bug with Apple.
I have filed a ticket with Apple here.
Any suggestions how to get around stale elements exceptions when it seems one shouldn't be raised? Fair enough with any of the many javascript libraries in use any updates may remove the respective DOM nodes and later FindElement from the disconnected node you can get a stale element.
The problem it seems, the tests in question i'm testing i know once displayed the content is static. Also the same code is working 100% with Firefox, but both the Chrome and Edge's WebDrivers (if not the same really close?) are giving unexpected "Stale Element Exceptions".
My code gets a node which is a parent for a given subtree holding information desired. For the parent node "Driver.FindElement()" is used but subsequent XPath queries are relative to the "parent" node.
For example given this DOM tree:
<node id='Closest node By ID'>
<span>
<div>text i want</div>
<div>ignore this</div>
<div>text to get</div>
</span>
<span>
<!-- same pattern ... -->
</span>
</node>
var parentNode = WebDriver.FindElement(ByID("ID"));
var txt1 = parentNode.FindElement(By.XPath("./span/div[1]");
var txt2 = parentNode.FindElement(By.XPath("./span/div[3]");
The problem is at some point performing the XPath quires will result in a 'stale element exception'.
I have working repro i'd be glad to share if someone could help look into this, getting into the WebDriver itself may be beyond me... Ping me will gladly provide a complete repro in C# details and whatever else may be needed.
Ah, and for vitals:
Chrome && WebDriver are both matched up.
Google Chrome is up to date, actually checking was 92, updated to 93 re-ran and same behavior.
Version 93.0.4577.63 (Official Build) (64-bit)
C# .Net framework 4.8
Win 10 "Version 21H1 (OS Build 19043.1202)"
Thanks in advance.
I am unable to interact with an element using browser tests. It says the element is not interact-able, or not visible. This doesn't happen in Acceptance
Sometimes this solution doesn't work because the element is unavailable for some other cryptic reason.
We just had a situation where we couldn't use a <select> element to pick one of the options.
Further more, there was behaviour that was being triggered by the "change" event when the option was selected.
We were able to solve it like this.
$js = "jQuery('#chosen-option-quantity-2').val('2').trigger('change');";
$I->executeJS($js);
so the first command selects the option, and the second triggers the change event.
I hope that helps some one, even if it is me in the future.
The problem that is happening here is that the html element is being hidden by something, probably css somewhere. Because it is hidden (display:none), WebDriver can't see it, and therefore can't interact with it.
In order to fix this problem, you need to use JS to un-hide the element.
use this $I->executeJS('jQuery("#your-css-selector").show()');
This doesn't happen in Acceptance tests because PHP Browser looks at the Page Source, and so can see everything, while WebDriver see's what a user see's on the browser.
You may use PhpBrowser
It works only with HTML then how PhantomJs emulate the real browser
But, with PhpBrowser you can't see what see your browser (only HTML such I said)
Another way, try executeJs with PhantomJs as it said before
I have a login page which loads just fine when above 767px wide and crashes the browser below that width. It only crashes when loading below that width, I can load at desktop width then size down just fine.
I have one div with .visible-desktop that contains the desktop login and superfluous stuff and another with .hidden-desktop containing only the mobile login. An image in the superfluous stuff is currently 404'ing. I'll fix it but it sure shouldn't be crashing the browser.
In the server console, the asset previous to the 404 asset loads and nothing else happens. In the browser, the page becomes unresponsive and crashes. Chrome just crashs and FF says
A script on this page may be busy, or it may have stopped responding. You can stop the script now, or you can continue to see if the script will complete.
Script: http://ccdev:3333/assets/jquery.js?body=1:6265
Update:
Using firebug and inserting a breakpoint on line 6348 in jquery v1.8.2 and stepping through it seems it's stuck incrementing something called elems. On one step the value will be something like "<li><a>177085</a></li>", on the next it will be "<li><a>177086</a></li>" and it never leaves that line. The line in question is
div.parentNode.removeChild( div );
This turned out to be an issue with Woothemes flexslider. jQuery can not remove items hidden by bootstrap. If loading the page at a width where flexslider is hidden, jquery has an infinite loop which will cause the browser to hang and crash.
I found the fix here. Just initialize flexslider with minItems: 1. Which should really be the default!
Solution:
Today (2011-04-13) handles Selenium RC the confirmation boxes under Firefox 4 badly.
I had to change back to Firefox 3.16 and then this problem disappears. Thanks again.
Original Question:
Hello Selenium gurus,
I am trying to execute an automated browser test from Java using Selenium 2.0b3 as the Java client and standalone server too.
The server starts a Firefox 4 with a specific profile.
The test is stuck at a "click" command; it waits and no timeout/exception/any error happens. During this click comes up a confirmation box, so I guess that is the problem, but I do not know why this gets stuck. In Selenium IDE comes not this confirmation box, only in RC.
The problem is not that, that the click does not happens (because the confirmation box appears), but that this confirmation box hangs.
I tried these but did not help:
selenium.click("css=div[id=command_Delete]");
selenium.click("id=command_Delete");
String JSscript = "jQuery('#command_Delete').click();" // See http://api.jquery.com/click/
selenium.runScript(JSscript);
These are just ways how to start the click.
Maybe I have to start a different Thread according these link: http://www.sqaforums.com/showflat.php?Cat=0&Number=567974&an=&page=0&vc=1
Thanks: Andras
Java code:
selenium.click("//div[#id='command_Delete']/span");
//stucks here
//so this is not reached:
String confirmation = selenium.getConfirmation();
HTML:
<div id="command_Delete" class="...">
<div>...</div>
<span>Delete</span>
<div>...</div>
<br><br>
</div>
Javascript:
<script type="text/javascript">
$('command_Delete').addEvent('click',function(){
var isConfirmTrue = confirm('Do you want to delete?');
if (isConfirmTrue) {
var myForm = getFormObj(document, "deleteForm");
submitForm(myForm);
}
});
</script>
And in the Java, it hangs waiting the selenium rc to answer:
HttpURLConnection.getInputStream() line: 912 [local variables unavailable]
HttpURLConnection(HttpURLConnection).getResponseCode() line: 367 [local variables unavailable]
HttpCommandProcessor.getResponseCode(HttpURLConnection) line: 147
HttpCommandProcessor.getCommandResponseAsString(String) line: 167
HttpCommandProcessor.executeCommandOnServlet(String) line: 107
HttpCommandProcessor.doCommand(String, String[]) line: 89
DefaultSelenium.click(String) line: 167
...
Have you tried replacing
selenium.click("//div[#id='command_Delete']/span");
with
selenium.click("id=command_Delete");
?
It seems to me that since the event is binded to the div itself that should work.
Additionally, you can execute the click action directly by doing this, I'm using jQuery since you seem to already have it loaded on the page and it makes things easier (especially for cross-browser testing):
String JSscript = "jQuery('#command_Delete').click();" // See http://api.jquery.com/click/
selenium.runScript(JSscript);
You'd just need to evaluate if this solution is good for you.
If a confirmation box is popping up the test will block until that confirmation box has been removed. You can do a quick manual test to see if this is your problem.
Run your test and when the confirmation box comes up manuall y interact with it, if everything else is fine the test should continue from that point as per normal.
Selenium is waiting for the page to load, but the pop up box is blocking the page from loading which is eventually resulting in a timeout.
You can try and work around this using selenium.chooseOkOnNextConfirmation(); before your click.
Are you sure your widget can afford a click?
I would try the CSS identifier:
selenium.click("css=div[id=command_Delete]");