Safari 12中的Selenium元素位置

问题描述 投票:1回答:1

我正在使用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;

我该如何解决这个问题?

c# selenium safari browserstack
1个回答
1
投票
        /* 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;
        }
© www.soinside.com 2019 - 2024. All rights reserved.