我正在使用BrowserStack在一系列设备/浏览器上运行Selenium测试,包括Safari 11,它运行正常。我现在正在尝试将Safari 12添加到测试中,但是从一开始我就遇到了麻烦:
System.Collections.Generic.KeyNotFoundException: 'The given key was not present in the dictionary.'
一旦我尝试获取第一个元素的位置。当它到达位置是System.Drawing.Point
时,以下将失败。
IWebElement element = this.Driver.FindElement(byLocator);
int x = element.Location.X;
我该如何解决这个问题?
/* 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;
}