Reputation: 31
I'm using BrowserStack to run Selenium tests on a range of devices/browsers, including Safari 11, and it works fine. I'm now trying to add Safari 12 to the tests but I'm having trouble right from the start since I'm getting:
System.Collections.Generic.KeyNotFoundException: 'The given key was not present in the dictionary.'
as soon as I try to get location on the first element. The following will fail when it reaches Location which is a System.Drawing.Point
.
IWebElement element = this.Driver.FindElement(byLocator);
int x = element.Location.X;
How do I get around this problem?
Upvotes: 1
Views: 285
Reputation: 410
/* Safari Hack */
int x;
int y;
try
{
x = element.Location.X;
}
catch (Exception)
{
x = ((OpenQA.Selenium.Remote.RemoteWebElement)element).LocationOnScreenOnceScrolledIntoView.X;
}
try
{
y = element.Location.Y;
}
catch (Exception)
{
y = ((OpenQA.Selenium.Remote.RemoteWebElement)element).LocationOnScreenOnceScrolledIntoView.Y;
}
Upvotes: 1