Selenium Webdriver: how to drag element to another iframe? - selenium

I am using Selenium chrome webdriver with java, I need help dragging an element out of an iframe and onto another element in a different iframe. Has anyone done this before and if so could you post an example for me?
Here is what I've tried so far, also I have tried many other solutions:
WebElement Atom = driver.findElement(By.xpath("//*[text()='Circle']"));
driver.switchTo().defaultContent();
driver.switchTo().frame("treeNavigation");
WebElement Event = driver.findElement(By.xpath("//*[text()='Line']"));
// Create Actions object passing in a WebDriver object
Actions builder = new Actions(driver);
// Chain some calls together and call build
Action dragAndDrop = builder.clickAndHold(Atom)
.moveToElement(Event)
.release(Event)
.build();
// Perform the actions
dragAndDrop.perform();

Haven't done that yet, but I would like to try the following;
move to the source iframe, get the element, clickAndHold, build, perform. Then switch to default content, then switch to target iframe, moveToElement, release, build, perform.
Any sample test page would help. Thanks.

Related

Selenium WebDriver -- Unable to click on hyperlink, click goes to the other element

I am unable to click on Website hyperlink, the click goes to Recently used pages.
Tried with CSS locator of Website icon [which works in the lower environment as it doesn't have Recently used pages] reference in it.
Tried with XPath Locator[including custom XPath], still, the click goes to another item.
Tried name locator.
Used Actions class for clicking.
Allowed the page to load completely by using sleep and WebDriver wait.
Located the element and send Enter keys, still Recently used pages is clicked.
Tried to click it using coordinates.
Thought of ChromeDriver issue but the issue persists in Firefox too.
Tried below XPath:
html/body/div/div[2]/div[2]/div[1]/a/div
//div[2]/div/a/div
Code snippet:
WebElement elementToClick = driver.findElement(By.cssSelector(".icon.siteadmin"));
elementToClick.click();
WebElement elementToClick = driver.findElement(By.cssSelector(".icon.siteadmin"));
(JavascriptExecutor)driver).executeScript("window.scrollTo(0,"+elementToClick.getLocation().x+")");
elementToClick.click();
WebElement elementToClick = driver.findElement(By.cssSelector(".icon.siteadmin"));
Actions actions = new Actions(driver);
actions.moveToElement(elementToClick);
actions.click().perform();
Actions builder = new Actions(driver);
builder.moveToElement(elementToClick, 40, 207).click().build().perform();
Result: It clicks on Recently Used Pages, and it yields a result of Recently used pages instead of Website.
UI Reference
Development Code Snippet
Hope It Helps you:
.//div[#id='box_2']/a/div[#class='icon siteadmin']/div[1]
Try the following:
driver.findElement(By.XPath(“//a[contains(#title, ‘Websites’)]”)).click()
If this doesn’t work use the above XPath in combination with one of the moves to element paths above and then use click.

How to resolve org.openqa.selenium.WebDriverException?

I am writing an automated test and want to report bugs, if occur, directly in the repo at GitHub. The step which fails in my program is the Submit new issue button from GitHub Issue Tracker.
Here is the code:
WebElement sendIssue = driver.findElement(By.xpath("/html/body/div[5]/div/div/div[2]/div[1]/div/form/div[2]/div[1]/div/div/div[3]/button"));
sendIssue.click();
And the exception:
org.openqa.selenium.WebDriverException: Element is not clickable at
point (883, 547.7999877929688). Other element would receive the click:
div class="modal-backdrop"></div
The following command also does not work:
((JavascriptExecutor) driver).executeScript("arguments[0].click();", sendIssue);
How can I make it clickable? Is there any other way by which I can resolve this issue?
This is happening because when selenium is trying to click ,the desired element is not clickable.
You have to make sure that the Xpath provided by you is absolutely right.If you are sure about the Xpath then try the following
replace
WebElement sendIssue = driver.findElement(By.xpath("/html/body/div[5]/div/div/div[2]/div[1]/div/form/div[2]/div[1]/div/div/div[3]/button"));
sendIssue.click();
with
WebElement sendIssue =(WebElement)new WebDriverWait(DRIVER,10).until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[5]/div/div/div[2]/div[1]/div/form/div[2]/div[1]/div/div/div[3]/button")));
sendIssue.click();
If that doesn't work ,You will get an Timeout exception, In that case try incaresing the timeout amount from 10 to 20.
If it still doesn't work please post a screenshot of the HTML.
You need to write something in the issue title and description to make the issue clickable are you sure you are not making that mistake of clicking the button without writing anything in those places I am adding screenshot for your convenience.
Selenium Webdriver introduced in a previous version (v2.48) a new behavior that prevent clicks on elements that may be overlapped for something else (a fixed header or footer - for example) or may not be at your viewport (visible area of the webpage within the browser window).
You can see the debate here.
To solve this you will need to scroll (up or down) to the element you're trying to click.
One approach would be something like this post:
Page scroll up or down in Selenium WebDriver (Selenium 2) using java
Another, and maybe more reasonable, way to create a issue on Github, would be using their API. Maybe it would be good to check out!
Github API - Issues
Gook luck.
This worked for me. Instead of HTML browser this would be useful if we perform intended Web Browser
// Init chromedriver
String chromeDriverPath = "/Path/To/Chromedriver" ;
System.setProperty("webdriver.chrome.driver", chromeDriverPath);
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless", "--disable-gpu", "--window-size=1920,1200","--ignore-certificate-errors");
WebDriver driver = new ChromeDriver(options);

Webdriver do not load scroll

I have a problem that is occuring some times.
The page is not showing the scroll, so when I need to find/click an element that is not shown in the screen, I get an exception:
(org.openqa.selenium.ElementNotVisibleException: element not visible
Refreshing the page works, but I would like to know if there is other solutions for this issue.
You can simulate scroll using moveToElement from Actions class
// Java syntax, but similar to other languages
Actions actions = new Actions(driver);
WebElement elementToMoveTo = driver.findElement(...);
actions.moveToElement(elementToMoveTo).perform();

Selenium DragnDrop not working properly

I am trying to moving a div with Selenium DragnDrop. Here is my Code
WebElement fromElement= driver.findElement(By.xpath("layoutDivPosition_locator"));
WebElement toElement=driver.findElement(By.xpath("layoutDivPosition_locator"));
Actions action = new Actions(driver);
Action dragnDrop = action.clickAndHold(fromElement).moveToElement(toElement).release(toElement).build();
dragnDrop.perform();
Please help for this .
Selenium's actions for drag and drop do not play nice with HTML5, when you trying to move element to some frame and in several other situations. Possibly you can solve your problem using this jQuery solution:
[C#][Selenium] How to drag-hover-drop an element

Selenium 2.0 / WebDriver clickAt() method unsupported

Selenium clickAt() function is throwing "Unsupported" exception while using with WebDriver (WebDriverBackedSelenium or just Selenium 2.x using ChromeDriver).
Is there any way to use this Selenium function via WebDriver?
Adding some code for context ...
ChromeDriver driver = new ChromeDriver();
driver.findElement(By.id("someID")).clickAt("25, 25");
.clickAt() method isn't even recognized ... however, using the WebDriverBackedSelenium is what provides the Unhandled exception.
You have to use Advanced User Interactions API
Click at the specific point inside an element looks like following:
ActionChainsGenerator builder = ((HasInputDevices) driver).actionsBuilder();
Action action = builder
.moveToElement(elementLocator, xOffset, yOffset)
.click()
.build();
action.perform();
At the moment, it is implemented for HtmlUnitDriver and InternetExplorerDriver only, other drivers are work in progress.
I have sometimes had similar problem and have fired the two MouseDownAt & MouseUpAt to solve the issue.. Seems as some JavaScript don't fire ok with clickAt always
Before you use click command on locator. you should use mouseOver on it.
Normally. this problem happen when link that need to click hidden or invisable.