Selenium Webdriver drag'n'drop from parent to child iframe - selenium

I've been looking for any working solution to drag'n'drop for the past 5 days.
So,
Selenium.WebDriver 2.44.0
WebDriver.ChromeDriver.win32 2.13.0.0
Chrome latest version.
C#, Page object pattern.
Sorry for russian descriptions on screens :)
We have .net cms. It has pages Editor. Editor opens in parent page, page to edit if loaded in iframe from the same domain.
I need to drag'n'drop items (pictures, video, etc) to a concrete containers in iframe.As far as I understood the following is used in CMS: This file contains following files: jQuery 1.11.1 + jQuery UI 1.10.4 + jQuery Migrate 1.2.1 */).
Piece of code: http://screencast.com/t/ArEk54ue
Here is a scenario during drag'n'drop:
In parent content I select some element id=someelement. (String is not active).
I click and hold on element, pulling it into iframe.
The following code appears in parent page:
Child element appear in String from the 1-st step. It's our element.
See screen: http://screencast.com/t/Cio4knwp
When I pull element to iframe onmouseover event fires and child string appear in the following string:
http://screencast.com/t/cpj3ihlE959
Containers change their color to green on mouseover.
Container code inside iframe:
http://screencast.com/t/Z6QBD6IYuB
What I've tried to do:
Simple webdriver drag'n'drop doesn't work since target element inside iframe.
Drag'n'drop by X,Y offset doesn't work too.
Drag'n'drop using Actions:
MoveToElement:
public Actions MoveToElement(IWebElement element)
{
var builder = new Actions(Webdriver);
return builder.MoveToElement(element);
}
source - picture which I pull
target - container.
WrapperSelenium.MoveToElement(source)
.ClickAndHold(source)
.Build()
.Perform();
WrapperSelenium.SwitchToFrame("WebsiteFrame");
WrapperSelenium.MoveToElement(target)
.Release(target)
.Build()
.Perform();
Doesn't work too.
4.I've tried to use some Javascript hacks, don't remember exactly what - no success.
Now I'm trying ro use jquery-simulate (https://github.com/j-ulrich/jquery-simulate-ext) - I can click an hold element, containers become active, but I can't release element and find target.
Please help!

I decided to use AutoIt - developers made to complex code structure

Related

How to move to geb page content that is not visible in the browser window?

How can I get the geb webdriver to move to an element on the page that may not be in the view of the browser. The element exists on the page and is displayed but there may be a possibility that the element will appear on the bottom of the page and the browser would need to scroll down in order to bring the element into view.
import geb.Page
class myPage extends Page {
static url = "mypage.xhtml"
static at = {title == "myPage"}
static content = {
someElement = {$("#bottomOfPage")}
anotherElement = {$(".someClass",5)}
}
void clickElement(){
//possibility to fail because element may not be displayed in browsers view
//if not in view, scroll to element, then click
someElement.click()
}
}
Using this page as an example, If an element is not in view on the page and possibly at the very bottom, how can I tell the webdriver to bring the element into view? I have some complicated tests that are failing when the page contents are not in view. In some cases, the driver will move to the element even if it's not in view. But I would like to explicitly tell the driver to move to an element if its not in view for the cases that it does not move on its own.
The selenium library does have a moveToElement() function but it only accepts objects of the WebElement class. Using geb, when creating page classes, all elements that are used in my tests are declared in the content section and thus are of the SimplePageContent class. SimplePageContent cannot be casted to a WebElement either. moveToElement(By.id("bottomOfPage")) does work but is not ideal because I do not want hard coded values. Id much rather pass the page content object itself if possible.
From my experience I can say that if you ask WebDriver to click on an element that is not currently in view it will first scroll to that element and then click on it. So you're either hitting some kind of bug if it does not happen or the fact that the element is not in view is not what's causing your element not to be clicked.
If you still want to move to the element explicitly using Actions.moveToElement() then you can easily turn objects returned from your content definition using the fact that they implement Navigator which comes with a firstElement() which you should use if you want to get the first WebElement of a multi element Navigator or singleElement() when your Navigator has exactly one WebElement.
There is also a simpler way, which won't require extracting WebElements from your Navigators - use an interact {} block:
interact {
moveToElement(someElement)
}

Unable to click button in mobile web in appium

After exhaustively searching for this over various forums, I still don't have an answer.
Here are complete details
I'm identifying the element through classname which points to multiple(4) buttons. I'm iterating through buttons and then search for text and when there is a match i click it.
This works fine with selenium webdriver and browsers such as firefox,chrome
Now I'm doing the same thing with appium.
Out of 4 buttons which are identified through classname, the script clicks 2 buttons successfully but for two buttons click happens(i can see the button being clicked) but new page which should be loaded is not loaded. The buttons for which click is not happening are in a footer class and other two are in div class.
Things i have already tried
Actions builder - click(), clickandhold()
Javascript executor
I'm currently trying with touch options, tap and by switching to native view but haven't found any success.
If any has encountered the same, a solution will be appreciated.
I want to avoid xPath because that might change in the page I'm working on, and I want to stress that the script is able to find the button, but is not able to click it properly.
You can filter your locator by using class name and index. Like this:
driver.findElementsByXPath("//*[#class='android.widget.ImageView' and #index='0']");
This xpath won't get change on other devices too.
Could you see: Unable to find an element in Browser of the Android emulator using Appium and C# ?
In case of testing web apps in browser the elements should be located as usual elements on the web page ( not as some classes like android.widget.EditText and android.widget.Button).
Upadting appium java client to 1.5.0 (from 1.3.0) solved the issue. Need to check why!

How to get Inspect Element code using Selenium WebDriver

I'm working in selenium with Firefox browser.
The Html code shown in View Source (CTRL+U) is different from the html code i see when inspecting the elements in Firefox.
When i run the driver.getPageSource() i only get the View source (CTRL + U) codes.
Is there is any way to access the Inspect element code instead of View source code?
I think your question is answered here.
The View Source html is what is sent by the server. I think of it as compile time html, or the initial state of the DOM.
The Inspect Element html could have been updated by ajax responses or javascript so will not necessarily be the same. I think of it as runtime html, or the current state of the DOM.
The GetAttribute() method queries the current DOM element state. You can return a particular html attribute value directly
webElement.GetAttribute("class")
or get the whole html string.
webElement.GetAttribute("innerHTML")
There are some fundamental difference between the markup shown through View Source i.e. using ctrl + U and the markup shown through Inspector i.e. using ctrl + shift + I.
Both the methods are two different browser features which allows users to look at the HTML of the webpage. However, the main difference is the View Source shows the HTML that was delivered from the web server (application server) to the browser. Where as, Inspect element is a Developer Tool e.g. Chrome DevTools to look at the state of the DOM Tree after the browser has applied its error correction and after any Javascript have manipulated the DOM. Some of those activities may include:
HTML error correction by the browser
HTML normalization by the browser
DOM manipulation by Javascript
In short, using View Source you will observe the Javascript but not the HTML. The HTML errors may get corrected in the Inspect Elements tool. As an example:
With in View Source you may observe:
<h1>The title</h2>
Whereas through Inspect Element that would have corrected as:
<h1>The title</h1>
getPageSource() always returns the markup obtained through View Source.

Selenium (WebDriver) cannot see richfaces modal panel

I'm having some issues trying to test elements inside a RichFaces modal panel, as the one
in the demo page of RichFaces here
the issue is that once retrieved an element I cannot interact with it because WebDriver throws a ElementNotVisibleException.
I check it with firebug, and it appears greyed out, because some of the divs have height and width set to 0.
I tried to set all the divs manually with a height and size to see if it changes but there is no way to make it work, so I suppose there must be something else affecting the visibility of the modal panel, but cannot find what.
Has anyone tested webdriver or selenium against a richfaces panel?
Thanks in advance.
Edit:
For the code, is too much to put here, but basically I adapted the jbehave tutorial for the etsy website (the one using spring to inject dependencies), that can be found here.
The architecture is using a PropertyWebDriverProvider that is configured by maven properties to use InternetExplorer or Firefox and is using PageObject pattern (all the pages extend from WebDriverPage).
For specific code, the one from JimEvans gives me the same error.
The following code seems to work for me using the demo site you linked to in your question. It gets the text content of the modal panel, then clicks the "button" to close the panel.
public void testPanel() {
WebDriver driver = new InternetExplorerDriver();
driver.get("http://livedemo.exadel.com/richfaces-demo/richfaces/modalPanel.jsf?c=modalPanel");
WebElement panelShow = driver.findElement(By.id("j_id352:link"));
panelShow.click();
WebElement panel = driver.findElement(By.id("j_id352:panelCDiv"));
WebElement panelTextElement = panel.findElement(By.className("rich-mpnl-body"));
System.out.println(panelTextElement.getText());
WebElement panelCloseButton = panel.findElement(By.id("j_id352:hidelink"));
panelCloseButton.click();
}
Only solution I found out was to do all the interaction with javascript through webdriver

Click DIV doesn't make a “real” click operation in IE

Browser: Internet Explorer 8 with compatibility view turned on (the tested application was written for IE7). I have a div element, which looks like a checkbox in the browser. When I manually click it the checkbox ticks itself. Here is how this looks like: http://img593.imageshack.us/g/divunchecked.jpg/ When clicked manually the div element also changes it's class attribute from "x-grid3-check-col" to "x-grid3-check-col-on". When I run a Watin test and make a Div.Click() operation the element doesn't check itself. Html of that element:
<DIV class=x-grid3-check-col onclick=booleanInterviewColumnRender_OnClick(this);> </DIV>
I have tried to:
- click 2 of the div's parents (it is placed in 2 other divs)
- Div.MouseDown();
Div.MouseUp();
- Div.Firevent("onclick");
- NameValueCollection eventProperties = new NameValueCollection();
eventProperties.Add("button", "0");
Div.FireEvent("onmousedown", eventProperties); //left mouse click
- Div.SetAttributeValue("class", "x-grid3-check-col-on");
Div.Refresh();
without luck.
Any ideas how to workaround this would be great.
The last workaround is to run directly the javascript call.
if you put an id on your div element: elementID
then you call
div.Document.Eval("document.getElementById(\"elementID\").fireEvent(\"onclick\")");
And it will call the onclick call back you put in your attribute (you can first try in the console to be sure that the javascript call your callback).
However, I think that the WatiN mehod .FireEvent on the Element does the same thing, so I don't understand why you need this workaround.