c# - Safari 12 中的硒元素位置
问题描述
我正在使用 BrowserStack 在一系列设备/浏览器上运行 Selenium 测试,包括 Safari 11,它运行良好。我现在正在尝试将 Safari 12 添加到测试中,但我从一开始就遇到了麻烦,因为我得到了:
System.Collections.Generic.KeyNotFoundException: 'The given key was not present in the dictionary.'
一旦我尝试在第一个元素上获取位置。以下将在到达 Location 时失败,这是一个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;
}
推荐阅读
- java - GCP IAP Java 示例返回 ComputeEngineCredentials 而不是 ServiceAccountCredentials
- javascript - 无法在 jQuery ajax 表数据中使用按钮 onclick 调用函数
- mysql - 多行mysql之间的查询
- php - 为什么在 PHP Session 中递增不起作用
- android - 单击通知时打开对话框 (FCM)
- html - 彼此放置4个div
- python-asyncio - 未知来源的未关闭客户端会话警告
- java - 用户向列表使用的字符串数组添加新单词(应用程序停止工作)
- swift - Swift:如何使用预处理器为*以下*某个 iOS 版本添加扩展方法?
- python-3.x - Keras 同时期望 2d 数组和 (1,) 的形状