Selenium WebDriver not working for Html5 drag and drop - html

Below is the code I am using, it will access one public website which is written using Html5,the code is trying to drag the "One" to trashbin, but it doesn't do anything. Is there any workaround to make it work? Thanks in advance!
FirefoxProfile profile = new FirefoxProfile();
profile.setEnableNativeEvents(true);
WebDriver driver = new FirefoxDriver(profile);
driver.get("http://html5demos.com/drag");
WebElement draggable = driver.findElement(By.id("one"));
WebElement droppable = driver.findElement(By.id("bin"));
new Actions(driver).dragAndDrop(draggable, droppable).build().perform();
Additional information is:
Selenium version: 2.25.0
OS: Mac OS Lion
Browser: Firefox
Browser version: 10.0.2 and 14.0.1

I would risk saying it is some sort of compatibility issue. I used the following code on http://jqueryui.com/demos/draggable/
System.setProperty("webdriver.ie.driver","C:\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("http://jqueryui.com/demos/draggable/");
WebElement draggable = driver.findElement(By.id("draggable"));
new Actions(driver).dragAndDropBy(draggable, 200, 10).build().perform();
and it worked like a charm on the IE9. However it did not work with my Firefox 14 which may be to "new".
You can also try some workaround using JavaScriptExecutor, sth like this is described here: HTML5 Drag and Drop using Selenium Webdriver for Ruby

Related

Selenium cannot find element

Having some issues using Selenium web driver in Chrome.
My goal is to give the user ~15-30 seconds to log in on there own and then start doing automated testing.
The problem is after I click the login button and go to the next page, I am not able to find elements by xpath, id, etc.
public static void runTest() throws InterruptedException {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("http://www.url.com");
driver.manage().window().maximize();
Thread.sleep(15000);
driver.findElement(By.xpath("//*[#id=\"content-main\"]/div/div/form/div/p/input")).click();
System.out.println("User has logged in and it has found element for Attachment Upload.");
Thread.sleep(15000);
driver.findElement(By.xpath("//*[#id=\"invoiceMenu\"]/a")).click();
}
I have also tried using explicit waits and have had no luck for example:
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(
ExpectedConditions.visibilityOfElementLocated(By.id("someid")));
The error I am usually getting back is:
Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.xpath: //*[#id="invoiceMenu"]/a (tried for 10 second(s) with 500 milliseconds interval)
Edit:
Was able to get some of the elements (angular ones) working with a few plugins for Chrome. Element Locator and ChroPath worked fantastic. Took some playing around with, but once I got one I was able to piece together the rest of them.
I would suggest that you open the chrome console on your browser and try to interact with the element in question e.g. using:
document.getElementById('someId').click()
If you are able to click on the element like that, then you can use javascript executor in your code as follows:
((JavascriptExecutor)driver).executeScript("document.getElementById('someId').click();");

SendKeys(Keys.Tab) does not work on Chrome Version 53.0.2785.116

Today I observed that SendKeys(Keys.Tab) does not working on Chrome webdriver. However it works perfectly on IE and FireFox. Other than Tab, i tried few other keys like Space, Backspace, Clear, some text, Enter etc working as expected on Chrome.
for example:
private IWebDriver driver;
private string baseURL;
driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://accounts.google.com/SignUp?");
driver.FindElement(By.Id("FirstName")).Clear();
driver.FindElement(By.Id("FirstName")).SendKeys(Keys.Tab);
Anybody know why, Keys.Tab won't working on latest Chrome Version 53.0.2785.116?
OS: Windows 7 Service Pack 1
The cursor suppose to move/focus to Last name text field
try to add code below at the end of your code:
var element = driver.FindElement(By.Id("FirstName"));
if (!element.Equals(driver.SwitchTo().ActiveElement())) return;
var js = (IJavaScriptExecutor)driver;
js.ExecuteScript("arguments[0].blur();", element);
It means if the cursor still focus on current element, trigger blur function to move to next element.

Adobe AIR bring to front - activate() not working

I have an adobe desktop AIR app. When I send some data with a local connection, I want the app in front of all the other windows with focus on it.
I tested on a brand new air app with just this code:
import flash.display.NativeWindow;
var window:NativeWindow = stage.nativeWindow;
var aspa = setInterval (activateWin,8000);
function activateWin (){
trace("Activate window");
window.activate();
clearInterval(aspa);
}
And nothing happens. While if I write:
window.alwaysInFront=true;
window.alwaysInFront=false;
It brings the app to the front, but this command gives no focus to the window.
If I add
NativeApplication.nativeApplication.activate(stage.nativeWindow);
This makes the status bar icon blink, but still no focus or front action.
Reading this page, it seems it should work.
Am I missing something?
I've just use
window.activate();
window.alwaysInFront = true;
window.alwaysInFront = false;
and it's works fine on windows and mac os

Element not clickable using Selenium webdriver with Chrome (same code:works fine using firefox)

Using selenium-2.44.tar.gz and chrome for automating test cases:Very strange my code works fine using Firefox 33 but fails using Google Chrome:
"WebDriverException: Message: u'unknown error: Element is not
clickable at point(57, 161). Other element would receive the click: ...\n
(Session info: chrome=42.0.2311.135 )\n (Driver info:
chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64)'"
self.driver.find_element_by_xpath(".//[#id='searchMessagstoryBtn']").click()
any idea? shouldnt it work better with chrome one wonders since webdriver is Google code nowdays or am I wrong!!!
Unlike firefox, to use chromedriver you have to download chromedriver from http://www.seleniumhq.org/download/ and had to give path in your code.
You can use the below code, to use chrome driver in java or in python
Java:
public void testGoogleSearch() {
// Optional, if not specified, WebDriver will search your path for chromedriver.
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com/xhtml");
Thread.sleep(5000); // Let the user actually see something!
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("ChromeDriver");
searchBox.submit();
Thread.sleep(5000); // Let the user actually see something!
driver.quit();
}
Python:
import time
from selenium import webdriver
driver = webdriver.Chrome('/path/to/chromedriver') # Optional argument, if not specified will search path.
driver.get('http://www.google.com/xhtml');
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()
It seems to be a bug in ChromeDriver.
http://code.google.com/p/selenium/issues/detail?id=2766
Try this workaround solution from form #27. I hope it would help you:
I ran into this same issue as well with Chrome...clicking the element
works fine in firefox but not in Chrome...the fix is pretty easy
though, all you have to do is scroll the element into view before
clicking it, and you won't run into this problem in Chrome. Here's the
code i use:
IWebElement elementToClick = ;
// Scroll the browser to the element's Y position (driver as
IJavaScriptExecutor).ExecuteScript(string.Format("window.scrollTo(0,
{0});", elementToClick.Location.Y));
// Click the element elementToClick.Click();
Hope this helps anyone else who runs into this issue
#FindBy(xpath = "//[#id='searchMessagstoryBtn']")
private WebElement Search_btn;
public WebElement getSearchBtnClick() {
return Search_btn;
}
public void Click_Search_Btn() {
//click the search button
TimeUnit.SECONDS.sleep(3);
getSearchBtnClick().click();
}

User Agent is not accessible in Internet Explorer 8 using ActionScript 3

I am using the code below to find the User Agent using ActionScript 3:
var userAgent:String = ExternalInterface.call("navigator.userAgent.toString");
The code is working in Firefox 13, Google Chrome & Opera, but the User Agent value as null in IE8.
Is there any code snippet that will work here or any other way to implement this?
toString is unnecessary, since userAgent is a string property. Use this syntax instead:
var userAgent:String = ExternalInterface.call("function(){return navigator.userAgent}")