简体   繁体   中英

C# Selenium Web Driver Exception after using SendKeys Function

Hi I am having problems with my web driver after using the SendKeys function.

What I am trying to do is after clicking an OK button on a dialogue box after clicking a 'Save' button on a webpage I am then trying to get the newly opened page's url.

My web driver is functioning correctly before using the SendKeys function, as I am able to click buttons, get urls etc.

I thought the issue might have been to do with the web page losing focus after clicking the OK button on the dialogue box so I used the following code (but this did not work either):-

> System.Collections.ObjectModel.ReadOnlyCollection<string> winHandle2 =
> _webDriver.WindowHandles;
> 
> _webDriver.SwitchTo().Window(winHandle[0]).SwitchTo();

The exception I am getting can be seen below:-

An exception of type 'System.InvalidOperationException' occurred in WebDriver.dll but was not handled in user code Additional information: [JavaScript Error: "a is null" {file: "file:///C:/Users/andrew.short/AppData/Local/Temp/anonymous.3779fc41a91f475c89d01937ed7bb71b.webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js" line: 8166}]'[JavaScript Error: "a is null" {file: "file:///C:/Users/andrew.short/AppData/Local/Temp/anonymous.3779fc41a91f475c89d01937ed7bb71b.webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js" line: 8166}]' when calling method: [nsICommandProcessor::execute] If there is a handler for this exception, the program may be safely continued.

I appreciate any help anybody can give me :-)

public static void SendKeys(this IWebElement element, string value, bool clearFirst)
{
    if (clearFirst) element.Clear();
    element.SendKeys(value);
}

This function is very simple, all it does is make our code a little from concise. In the original Selenium RC, SendKeys would clear a text field and then send the required text. In Selenium 2, text fields are not cleared first unless explicitly executed. We can then combine it to allow something like:

myElement.SendKeys("populate field", clearFirst: true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM