I have using recursiveTreeNodesAdaptor in seam. And I want to add child this tree via contextMenu and when user click right node of tree open context menu and click left then open modal panel. I want to do this.
When I try to write selenium test this flow I dont click to rigt and open contextMenu. I try to selenium.contextmenu(xpath) but i'm fail.
So, How can I click to right
I tried to simulate right click with user extension. My function is below:
Selenium.prototype.doContextMenuClick = function(element){
var evt = document.createEvent('MouseEvents');
var RIGHT_CLICK_BUTTON_CODE = 2; // the same for FF and IE
evt.initMouseEvent('contextmenu', true, true,
document.defaultView, 1, 0, 0, 0, 0, false,
false, false, false, RIGHT_CLICK_BUTTON_CODE, null);
if (document.createEventObject){
// dispatch for IE
return document.fireEvent('onclick', evt);
}
else{
// dispatch for firefox + others
return !document.dispatchEvent(evt);
}};
I managed to call the function from IDE. But, now, I get the error "this.waitForCondition is not a function". What's wrong? Do you have any idea?
Thanks in advance.
Try using fireEvent on that element.
You should also take a look at this post which seems to be about the same issue.
The latest selenium has a namespace called OpenQA.Selenium.Interactions Namespace. check it out here.
see my other post here
Related
Problem : Mouse hover action is not highlighting the element . We are using selenium's mousehover() method.
What we tried : We tried the three solutions given in http://toolsqa.com/selenium-webdriver/mouse-hover-action/ link but none of it worked to achieve the goal.
Please let us know your advise or suggestion for achieving this.
which browser you are using because if you are using firefox and selenium 3.5 there is an issue regarding mouse actions which they are looking into it. I suggest try running it in chrome and check
Try JavaScript for mouse hover. Please give below code try and let me know if its works:
string javaScript = "var evObj = document.createEvent('MouseEvents');" +
"evObj.initMouseEvent(\"mouseover\",true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);" +
"arguments[0].dispatchEvent(evObj);";
JavascriptExecutor js = = (JavascriptExecutor)driver;
//Pass element on which mouse hover to be performed
js.executeScript(javaScript,element)
Pass you webelement in above line on which you want to perform mouse hover.
I'm using dijit.dialog to show the popup dialog. How do I refresh the parent page on closing dijit.Dialog? Please advise. thanks
You need to add a listener to the hide event, and you need location.reload(). It will be a lot easier to answer your question if you post some code and list what you've tried already.
Here's a jsfiddle illustrating how to use location.reload() when a dijit/Dialog closes with Dojo 1.8.
The relevant code:
d.on('hide', function() {
console.log('closed');
location.reload();
});
You can use code as below, you just need to now your modal object's name.
var dialog = registry.byId("modalDialogObjectName");
var url = dialog.get("href");
dialog.set("href", url);
Using the Codeception testing framework and Selenium 2 module to test a website, I end up following a hyperlink that opens a new window with no name. As a result the switchToWindow() function will not work because it is trying to switch to the parent window (which I'm currently on). Without being able to switch to the new window I cannot perform any testing on it.
<a class="external" target="_blank" href="http://mylocalurl/the/page/im/opening">
View Live
</a>
Using both Chrome and Firefox debugging tools I can confirm the new window doesn't have a name, and I cannot give it one because I cannot edit the HTML page I am working on. Ideally I would have changed the HTML to use javascript onclick="window.open('http://mylocalurl/the/page/im/opening', 'myPopupWindow') however this is not possible in my case.
I've looked around on the Selenium forums without any clear method to tackle this problem, and Codeception doesn't appear to have much functionality around this.
After searching around on the Selenium forum and some helpful prods from #Mark Rowlands, I got it to work using raw Selenium.
// before codeception v2.1.1, just typehint on \Webdriver
$I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
$handles=$webdriver->window_handles();
$last_window = end($handles);
$webdriver->focusWindow($last_window);
});
Returning back to the parent window was easy because I could just use Codeception's switchToWindow method:
$I->switchToWindow();
Building on the accepted answer, in Codeception 2.2.9 I was able to add this code to the Acceptance Helper and it seems to work.
/**
* #throws \Codeception\Exception\ModuleException
*/
public function switchToNewWindow()
{
$webdriver = $this->getModule('WebDriver')->webDriver;
$handles = $webdriver->getWindowHandles();
$lastWindow = end($handles);
$webdriver->switchTo()->window($lastWindow);
}
Then in the test class I can do this:
$I->click('#somelink');
$I->switchToNewWindow();
// Some assertions...
$I->switchToWindow(); // this switches back to the previous window
I had a heck of a time trying to figure out how to do this by just searching google, so I hope it helps someone else.
Try this,
String parentWindowHandle = browser.getWindowHandle(); // save the current window handle.
WebDriver popup = null;
Iterator<String> windowIterator = browser.getWindowHandles();
while(windowIterator.hasNext()) {
String windowHandle = windowIterator.next();
popup = browser.switchTo().window(windowHandle);
}
make sure to return on parent window using,
browser.close(); // close the popup.
browser.switchTo().window(parentWindowHandle); // Switch back to parent window.
I hope will help you.
Using Codeception 2.2+ it looks like this:
$I->executeInSelenium(function (\Facebook\WebDriver\Remote\RemoteWebDriver $webdriver) {
$handles = $webdriver->getWindowHandles();
$lastWindow = end($handles);
$webdriver->switchTo()->window($lastWindow);
});
I am working on testing an application with open layers maps using Selenium IDE. I researched a lot about clicking on the specific point on the map but I couldn't do it. Can you please provide me some start on this.
Thanks in advance.
Regards,
Rakesh
if you don't want to change the open layers code from Selenium IDE you can run your own javaScript functions by using "runScript" as a command and write your javaScript code into the target field (don't use comments as everything is written in one line).
use the following script to fire a mousedown, mouseup and if you need a click event on the map:
var mousedownEvent = document.createEvent('MouseEvents');
mousedownEvent.initMouseEvent('mousedown', true, true, window, 0, 0, 0, yourX, yourY, false, false, false, false, 0, null);
// creates an element from where the clickEvent can be fired
// instead of using pixel you can also refer to your dom-Element by id
document.elementFromPoint(16,118).dispatchEvent(mousedownEvent);
var mouseupEvent = document.createEvent('MouseEvents');
mouseupEvent.initMouseEvent('mouseup', true, true, window, 0, 0, 0, yourX, yourY, false, false, false, false, 0, null);
// same element
document.elementFromPoint(16,118).dispatchEvent(mouseupEvent);
// in some cases a click event needs to be fired as well
I am working on creation of automated test for some Web Application. This application is very complex. In fact it is text editor for specific content. As a part of functionality it has some pop-up frames. You may open this pop-up? make some changes and save them - closing current frame. May problem is in that fact, that close button situated inside frame will be eliminating. And this force Chrome WebDriver to hung. My first try was like this:
driver.findElement(By.xpath("//input[#id='insert']")).click();
driver.switchTo().defaultContent();
But it hungs on first line after executinh click command as this command close frame.
Then I change to this(I have JQuery on the page):
driver.executeScript("$(\"input#insert\").click()");
driver.switchTo().defaultContent();
But this leads to same result.
Then I use this solution:
driver.executeScript("setTimeout(function(){$(\"input#insert\").click()}, 10)");
driver.switchTo().defaultContent();
And it hungs on second line. Only this solution works:
driver.executeScript("setTimeout(function(){$(\"input#insert\").click()}, 100)");
driver.switchTo().defaultContent();
but only if you don't take into account, that it is unstable - some timing issue may occur.
So may question is there more cleaner and more stable way for switch out from closed frame?
P.S.: executeScript - self defined function to decrease amount of code. It simply executer some js on page.
Update:
I realized I was wrong. This problem is not for all iframes. It's occur when tinyMCE popup used. Situation is exactly like in this topic. So it's doubtful I will find answer here, but who knows. Solution described above will help, but only for very short amount of time, meaning that after several seconds pass chromedriver will hangs on next command.
This is how i would do it in Ruby, hopefully you can change it for java
$driver.find_element(:xpath, "//input[#id='insert']").click
$wait.until {$driver.window_handles.size < 2} #this will "explicitly wait" for the window to close
handles = $driver.window_handles #get available window handles
$driver.switch_to.window(handles[0]) #navigate to default in this case the First window handle
hope this helps
Problem was in this line of tinyMCEPopup code:
DOM.setAttrib(id + '_ifr', 'src', 'javascript:""'); // Prevent leak
Executing this script on page fix hang problem(but possibly creates leaks :) ):
(function() {
var domVar;
if (window.tinymce && window.tinymce.DOM) {
domVar = window.tinymce.DOM
}
else if (window.tinyMCE && window.tinyMCE.DOM) {
domVar = window.tinyMCE.DOM
}
else {
return;
}
var tempVar = domVar.setAttrib;console.log(123)
domVar.setAttrib = function(id, attr, val) {
if (attr == 'src' && typeof(val)== 'string' &&(val + "").trim().match(/javascript\s*:\s*("\s*"|'\s*')/)) {
console.log("Cool");
return;
}
else {
tempVar.apply(this, arguments);
}
}
}());
Bug and solution also described here
Note. Code above should be added to parent frame, not into popup frame.