简体   繁体   English

如何使用 C# 在 Selenium 中使元素显示为真

[英]How to make element displayed to true in Selenium using C#

I want to click an excel button on a page but i am getting "element not interactable" error.我想单击页面上的 excel 按钮,但出现“元素不可交互”错误。
When i debugged it, i see the element display is set to false.当我调试它时,我看到元素显示设置为 false。 However, i can go to the page and click element and it downloads the file so it works but not when i am running my code.但是,我可以 go 到页面并单击元素,它会下载文件以便它可以工作,但在我运行我的代码时却不行。 I have put longer wait time but that did not help either.我放了更长的等待时间,但这也无济于事。 Here is my code这是我的代码

  var excelButton = driver.FindElement(By.XPath("//div[contains(@class,'exportLabel') and contains(text(),'XLS (1000 max)')]"));
       
        System.Threading.Thread.Sleep(5000);
        excelButton.Click();

在此处输入图像描述

I believe if user us able to click manually, then script should be also able to click it.我相信如果用户我们能够手动点击,那么脚本也应该能够点击它。 I think, your page is rendering and during the rendering process the script is executing or browser has not completed its job and script executed.我认为,您的页面正在渲染,并且在渲染过程中脚本正在执行或浏览器尚未完成其工作并且脚本已执行。

just make sure you are selecting the right div and right element using xpath in case if you have two different div with same control tag and class.只要确保您使用 xpath 选择正确的 div 和正确的元素,以防您有两个具有相同控制标签和 class 的不同 div。

let me know if i am of any help让我知道我是否有任何帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM