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

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.

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();");

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();
}

App doesn't not work when released as valid. Bug?

I'm working on an app since a long time ago, i've never been able to released it but I was still coding it. I'm working on flash builder and when debbuging everything is perfect, when exported I only can watch the color of the stage background. As I couldn't use Trace outside of the debugger I converted all my classes as Sprites to check where the issue come from by displaying a textfield.
But I still can't understand. This is okay (in debugger and released) :
b = new TextField;
b.text = "Mytext";
addChild(b);
var fetch:Fetch_Tiles = new Fetch_Tiles(arr, "Ground", "Tiles");
This is not Okay (of course, in debugger everything works well):
var fetch:Fetch_Tiles = new Fetch_Tiles(arr, "Ground", "Tiles");
b = new TextField;
b.text = "Mytext";
addChild(b);
And, when I say "not Okay" means that my text is not displayed. And the entire following part of my app (so, nothing).
I have to guess that there is a bug coming from that Fetch_Tiles object, bug accepted by the debugger but not when released (???).
But, worse, when trying to display this text in the constructor of my Fetch_Tiles, like this :
private var b:TextField;
function Fetch_Tiles($names:Array, $dir:String, $sub:String) {
b = new TextField;
b.text = "Mytext";
addChild(b);
...
The same, it works with debugging, not with valid.
Can someone explains me ?...
thanks to shaunhusain I discover where the issue does come from, it's not a bug (of course not) but the exception #2148 my browser never show me. I dunno why but my app is not trusted, even in local, to load datas... I could get rid of that exception using this hack -use-network=false putted in the compiler.
http://curtismorley.com/2007/08/31/flash-cs3-flex-2-as3-error-2148/

Selenium WebDriver not working for Html5 drag and drop

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

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}")