The same method used in the test automation project I wrote in c # does not work in internet explorer 11 even though the movement method I use is chrome, firefox and edge. It does not give any errors, but the next action is fail
log.Debug("fare " + by + " üzeriine dogru haraket ediyor, webelement label ");
IWebElement element = GetElement(by);
Actions Actions = new Actions(Driver);
WaitElementToClickable(Driver, by, 5);
Actions.MoveToElement(element);
Actions.Perform();
WaitElementToClickable(Driver, by, 5);
I spent a long time trying to get actions to work across all browsers, and for IE I found the following helped.
Selenium webdriver v2.29.0 (https://github.com/SeleniumHQ/selenium/blob/master/java/CHANGELOG) added:
IEDriver supports "requireWindowFocus" desired capability. When
using this and native events, the IE driver will demand focus and
user interactions will use SendInput() for simulating user
interactions. Note that this will mean you MUST NOT use the
machine running IE for anything else as the tests are running.
When I set the IEDriver I use:
InternetExplorerOptions options = new InternetExplorerOptions();
options.requireWindowFocus();
webDriver = new InternetExplorerDriver(options);
And all my move to and click events work fine. I'm using IE11.125-11.309 and Selenium (java bindings) 3.7.1.
class Program
{
static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver();
//Dev environment
driver.Url = /*URL*/;
var trialGroupName = driver.FindElement(By.Name("TrialGroupName"));
trialGroupName.SendKeys(/*trial group name */);
var userName = driver.FindElement(By.Name("UserName"));
userName.SendKeys(/*username*/);
var password = driver.FindElement(By.Name("UserPassword"));
password.SendKeys(/*password*/);
var loginButton = driver.FindElement(By.Id("Ok"));
loginButton.Click();
//Find and click on Browse tab
var browseTab = driver.FindElement(By.Id("17"));
browseTab.Click();
}
}
OpenQA.Selenium.NoSuchElementException: 'no such element: Unable to locate element: {"method":"id","selector":"17"}
(Session info: chrome=58.0.3029.110)
(Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64)'
Here's the inspect information:
<td>
<a id="17" class="defaultMenu initMenu" href="javascript:onMenuHref(17)" notran="">Browse</a>
</td>
I've also tried running it with the XPath (both the short version from Chrome and the long version from FireBug) and I receive the same error. I've tried adding in an implicit wait and a Thread.Sleep() but still received the same error. Also tried starting on a different field and tabbing to it and then it gave me the same exception but on the new field. I also tried playing around with cssSelector this morning and couldn't get that to work either. I did try to do an explicit wait but I'll be honest, I'm still trying to digest and understand it as waits are a new concept and I don't fully understand it, so I don't think I'm doing it right.
I'm a beginner, and I'm currently just trying to write the script to get it to the actual page that needs testing. I've been teaching myself some coding and selenium as I'm the only QA person at my company right now and I really think we could benefit from automation. This portion of the page isn't actually programmed by us it's done by a third party who hosts the system we use so I'm limited to what I see in the inspect.
(I commented out the user login information and URL because it is for internal use only and the page can't be reached outside of our systems anyways. Also I'm pretty sure I'm not allowed to do so by my employer).
Any help on this would be greatly appreciated, or any additional resources I can use. I've been using google mostly so there may be other pages you are aware of that could help me that I haven't found yet.
The login button takes you to a new page, which you need to wait for it to load. Try using an explicit wait to wait for the tab to be clickable. The timeout is 10 seconds in the following example, so modify that as needed.
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement browseTab = wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("17")));
I have an issue when switching from ChromeDriver to PhantomJSWebDriver, that I need a workaround for.
Using the ChromeDriver I perform a .Click on a visible element, with another visible element next to it. the .Click makes the web page place a 'popup' over these elements. I then perform a .Click on an element within this 'popup' and it then goes away, and I am able to perform a .Click on the second of the original elements and it all works fine.
However, when I switch to using the PhantomJSDriver it complains that the second element is NOT visible after the 'popup' has been removed, and so wont do the .Click.
Is this a known issue with the PhantomJS driver, or is there some way to get it to 're-evaluate' what is visible? I have tried using a DriverWait looking for the element and waiting for it to be 'Displayed' but that doesn't work
WebDriverWait waitforpopdown = new WebDriverWait(driver, TimeSpan.FromSeconds(15));
waitforpopdown.Until(d => {
var elpd = driver.FindElement(By.ClassName(trid));
return elpd.Displayed;
});
I'm using PhantomJS 2.1.1 and Selenium 2.52.0.0 and using C#
I had the same problem with PhantomJSDriver. It hasn't the same javascript engine than Chrome, FF and IE.
I "fixed" my problem by installing a selenium server that is running chrome on a docker. If you have the ability to do that, I would recommend to work that way. It's an actual chrome browser that is running, so you don't have any difference between your different types of chromes.
You can find information about it on the following page : https://github.com/peroumal1/docker-chrome-selenium
EDIT : You have to declare your driver like this (note that it's java Syntax, but I'm sure you'll be able to find the C# syntax) :
return new RemoteWebDriver(new URL("http://myurl.url:8888"), DesiredCapabilities.chrome());
I have the following program:
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Edge;
namespace ConsoleApplication1
{
static class Program
{
static void Main()
{
//var driver = new ChromeDriver();
var driver = new EdgeDriver();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));
driver.Navigate().GoToUrl("http://www.cornelsen.de/shop/registrieren-lehrer");
driver.FindElement(By.Id("email")).SendKeys("dummy#user.de");
}
}
}
When I run this in Chrome or any other browser aside from Edge, then the email adress is entered correctly. But if I try the same thing in Edge, the "#" character is missing. The field displays only "dummyuser.de".
Any idea what I can do?
As a workaround, you can set the input value directly via ExecuteScript():
IWebElement email = driver.FindElement(By.Id("email"));
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
string script = "arguments[0].setAttribute('value', 'arguments[1]');";
js.ExecuteScript(script, email, "dummy#user.de");
Or, what you can do is to create a fake input element with a predefined value equal to the email address. Select the text in this input, copy and paste into the target input.
Not pretty, but should only serve as a workaround:
// create element
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
string script = #"
var el = document.createElement('input');
el.type = 'text';
el.value = 'arguments[0]';
el.id = 'mycustominput';
document.body.appendChild(el);
";
js.ExecuteScript(script, "dummy#user.de");
// locate the input, select and copy
IWebElement myCustomInput = driver.FindElement(By.Id("mycustominput"));
el.SendKeys(Keys.Control + "a"); // select
el.SendKeys(Keys.Control + "c"); // copy
// locate the target input and paste
IWebElement email = driver.FindElement(By.Id("email"));
email.SendKeys(Keys.Control + "v"); // paste
It wasn't as easy as I thought after all. Issues with alecxe's answer:
arguments[0].setAttribute('value', '...'); works only the first time you call it. After calling element.Clear();, it doesn't work any more. Workaround: arguments[0].value='...';
The site doesn't react on the JavaScript call like it would on element.SendKeys();, e.g. change event is not invoked. Workaround: Send the first part of the string up to the last "forbidden" character via JavaScript, the rest via WebElement.SendKeys (in this particular order, bc if you do another JavaScript call to the same field after SendKeys(), there will occur no change event either).
I also realized that there are more "forbidden" characters in Edge, e.g. accented or Eastern European ones (I'm Central European). The problem with 2. is that the last character might be a forbidden character. In this case, I append a whitespace. Which of course affects the test case behavior, but I haven't had any other idea.
Full C# code:
public static void SendKeys(this IWebElement element, TestTarget target, string text)
{
if (target.IsEdge)
{
int index = text.LastIndexOfAny(new[] { '#', 'Ł', 'ó', 'ź' }) + 1;
if (index > 0)
{
((IJavaScriptExecutor) target.Driver).ExecuteScript(
"arguments[0].value='" + text.Substring(0, index) + "';", element);
text = index == text.Length ? Keys.Space : text.Substring(index);
}
}
element.SendKeys(text);
}
This problem used to occur in old browsers. Apparently it returned in Edge.
You can try sending the string in pieces
IWebElement email = driver.FindElement(By.Id("email"));
email.SendKeys("dummy");
email.SendKeys("#");
email.SendKeys("user.de");
Or try using # ASCII code
driver.FindElement(By.Id("email")).SendKeys("dummy" + (char)64 + "user.de");
Try to clear the Text field first.
try following
driver.FindElement(By.Id("email")).clear().SendKeys("dummy#user.de");
Have you tried Copy Paste?
Clipboard.SetText("dummy#user.de");
email.SendKeys(OpenQA.Selenium.Keys.Control + "v");
Hope it could help.
I just added one extra line to click on text field and then send keys, I tried this and its working for me.
Code is written in java, you can change that to any other, if you want.
//INITIALISE DRIVER
WebDriver driver = null;
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.navigate().to("http://www.cornelsen.de/shop/registrieren-lehrer");
driver.manage().window().maximize();
//CLICK EMAIL FIELD, JUST TO HAVE FOCUS ON TEXT FIELD
driver.findElement(By.id("email")).click();
driver.findElement(By.id("email")).sendKeys("dummy#user.de");
I'm the Program Manager for WebDriver at Microsoft. I just tried to reproduce your issue on my home machine (Windows 10 build 10586) and couldn't reproduce. Your exact test entered the '#' symbol fine.
You should check if you have the latest version of Windows 10 and WebDriver. If you hit the Windows key and type "winver" and hit enter it'll open a popup with the Windows version info. You want it to say
Microsoft Windows
Version 1511 (OS Build 10586.104)
This is the latest version of Windows 10 released to the public. If you have this version you'll also need the corresponding version of WebDriver found here:
http://www.microsoft.com/en-us/download/details.aspx?id=49962
Note that if the build is 10240 that you're on the original release build. Our November update added substantial support for new features (like finding elements by XPath and more!) along with bug fixes which might explain your issues.
Lastly I should note we have an Insiders release as well for WebDriver to match with the Insiders program. If you're subscribed to the Insiders program and want to see the newer features and bug fixes for WebDriver you can find the download here:
https://www.microsoft.com/en-us/download/details.aspx?id=48740
Note that it currently supports build 10547 which was actually before the November update. It'll be updated very shortly (next couple of days) to support the latest Windows Insiders flight, build 14267.
Sorry but I not agree with the last comment (Program Manager for WebDriver at Microsoft). I can reproduce the problem. This is my configuration:
Target Machine (Hub node where tests are run):
Win 10 build 10585.104
MS Edge 25.10586.0.0
MS EdgeHTML 13.10586
Selenium framework:
SeleniumHQ (for Java): 2.48.0
I am using Selenium Grid to run my suite. In this case, I was only doing conceptual test of Egde implementing a basic test:
1. Start Hub in local machine (Win 7) opening console (administrator privileges)
2. Register Node in Hub in target remote machine (Win 10 build 10585) opening console (in this case without administrator privileges because in other way edge hangs when create new session).
Setting up my grid and checking that everything is ok when I try to write my account name in login page I can not see the # and my basic test fails (wrong credentials).
I have introduced # by hand in the moment edge is opened (interrupt point) and I can see symbol.
I have sent "###############" to the text field and I can not see any. In summary, I have tried many things and I can not see #
When I started with Web Automation Testing using Selenium (Java) I remember this behaviour in old versions of Firefox and Chrome. I not really sure which one but it was reproducible in old version.
This partial basic code (implementated with pageobject) IS WORKING with Firefox 35.0 and Chrome 48.0.2564.109 but NOT IS WORKING with Edge's version I put at the beginning of my comment.
WebElement element = WebDriverExtensions.findElement(context, By.cssSelector("input[name='username'][type='email']"));
element.clear();
element.sendKeys(email);
Front Developers are using AngularJS and are validating user's text input to match with a welformatted email:
I afraid that current Edge version does not support sendkeys with this kind of character, maybe the problem is front on-line validation and Edge has to suits these situations because they are really common.
Best regards
None of the above worked for me with the version 2.52. This worked for me :
EdgeDriver edgeDriver = new EdgeDriver("folder of my edge driver containing MicrosoftWebDriver.exe");
IJavaScriptExecutor js = _edgeDriver as IJavaScriptExecutor;
js.ExecuteScript("document.getElementById('Email').value = 'some#email.com'");
Make sure to replace the ".getElementById('Email')" with what you should use to find your field with javascript and replace the "folder of my edge driver containing MicrosoftWebDriver.exe" with the correct path.
Good luck!
I have an input element that opens a new popup window when clicked (where the user can select a value for the field).
Markup:
<html>
<input type="text" id="myPopup" readonly="readonly" name="myPopup">
</html>
c#:
var driver = new PhantomJSDriver(#"C:\PhantomJS");
driver.Navigate().GoToUrl(#"http://username:password#localhost/myUrl.aspx");
var popupField = driver.FindElementById("myPopup");
popupField.Click();
(I'm passing credentials in the URL for Windows Authentication)
I get a WebDriverException:
"The HTTP request to the remote WebDriver server for URL ...element/:wdc:1389663237442/click timed out after 60 seconds."
All other interactions I tried work except this particular element. Also tried with IE/Chrome drivers and it worked.
Any ideas?
PhantomJS 1.9.2,
C# / GhostDriver,
Selenium Webdriver 2.39,
Windows 7 x64.
Let me know if there's any other info I can provide.
I had a similar issue. Tests worked on FF but timed out on PhantomJs, as you describe. The pages I was testing used a lot of social media plugins which I think were using XHR. Removing most of the security restrictions on PhantomJs fixed it for me (see below).
service.IgnoreSslErrors = true;
service.WebSecurity = false;
service.LocalToRemoteUrlAccess = true;
service.DiskCache = true; // Dunno what this does but I thought it might help.
PhantomJSDriver driver = new PhantomJSDriver(service);