Selenium,无法单击 DEVOPS 上的元素

发布于 2025-01-16 20:49:20 字数 1730 浏览 1 评论 0原文

我在页面上有 FontAwesomeIcon 反应元素。当我在本地运行测试时,它通常可以工作,这意味着它找到元素并执行单击操作。 当我在 DevOps 测试中运行相同的场景时,它不可交互。 我尝试以多种方式运行点击操作,但没有任何效果。 代码

IWebElement btnSearchLocalization = driver.FindElement(By.CssSelector(".fa-1x"));
executorEventPlace.ExecuteScript("arguments[0].scrollIntoView(true);", btnSearchLocalization);
IWebElement btnSearchLocalization2 = driver.FindElement(By.CssSelector(".fa-1x"));

btnSearchLocalization2.Click();

我在交互元素方面遇到了很多其他问题,但在大多数情况下帮助了这两个解决方案之一:

executorEventPlace.ExecuteScript("arguments[0].scrollIntoView(true);", eventPlace);
executorEventPlace.ExecuteScript("arguments[0].click();", eventPlace);

如何正确设置 devops 代理?如何与我本地电脑进行比较?我还添加了很多 Thread.Sleep() ,但这些元素必须是可见的。

编辑 初始化:

public static IWebDriver _driver;
 public static IWebDriver Instance
    {
        get
        {
            if (_driver == null)
            {
                ChromeOptions options = new ChromeOptions();
                //options.AddArguments("start-maximized");
                //options.AddArguments("--window-size=1920,1080");
                options.AddArguments("--start-maximized");
                options.AddArgument("--ignore-certificate-errors");
                options.AddArgument("--disable-popup-blocking");
                options.AddArgument("--incognito");

                _driver = new ChromeDriver(@"C:\temp\chromedriver\", options);
                //_driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), options);
            }
            return _driver;
        }
    }

异常: OpenQA.Selenium.ElementNotInteractableException:元素不可交互:元素当前不可见,并且可能无法操作 (会话信息:chrome=99.0.4844.84)

I have FontAwesomeIcon react element on page. When I run tests locally it normally works it means it finds element and do Click action.
When I am running the same scenarious in devops tests it is not interactable.
I tried to run click action in a lot of ways but nothing works.
CODE

IWebElement btnSearchLocalization = driver.FindElement(By.CssSelector(".fa-1x"));
executorEventPlace.ExecuteScript("arguments[0].scrollIntoView(true);", btnSearchLocalization);
IWebElement btnSearchLocalization2 = driver.FindElement(By.CssSelector(".fa-1x"));

btnSearchLocalization2.Click();

I got a lot of other problems with interacting elements but in most of cases helped one of this two solutions:

executorEventPlace.ExecuteScript("arguments[0].scrollIntoView(true);", eventPlace);
executorEventPlace.ExecuteScript("arguments[0].click();", eventPlace);

How to setup devops agent correctly? How to compare it with my local computer? I also added a lot of Thread.Sleep() but this elements must be visible.

Edit
Initialization:

public static IWebDriver _driver;
 public static IWebDriver Instance
    {
        get
        {
            if (_driver == null)
            {
                ChromeOptions options = new ChromeOptions();
                //options.AddArguments("start-maximized");
                //options.AddArguments("--window-size=1920,1080");
                options.AddArguments("--start-maximized");
                options.AddArgument("--ignore-certificate-errors");
                options.AddArgument("--disable-popup-blocking");
                options.AddArgument("--incognito");

                _driver = new ChromeDriver(@"C:\temp\chromedriver\", options);
                //_driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), options);
            }
            return _driver;
        }
    }

Exception:
OpenQA.Selenium.ElementNotInteractableException : element not interactable: Element is not currently visible and may not be manipulated
(Session info: chrome=99.0.4844.84)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文