How can i get display:none element using Selenium Webdriver c#?

吃可爱长大的小学妹 提交于 2021-02-07 17:33:16

问题


enter image description here

Please provide me the scripting code in C# to get the text of the element that are marked in blue box. I am using Selenium Web driver and I want to get the value:10975 in the td tag.

I tried the following code:

         IWebElement tableLocator = divLocator.FindElement(table);
         IWebElement tbodyFind = tableLocator.FindElement(tbodytag);
         driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
         wait.Until(ExpectedConditions.ElementIsVisible(trTag));
         List<IWebElement> trList = tbodyFind.FindElements(trTag).ToList();
         driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
         wait.Until(ExpectedConditions.ElementIsVisible(tdTag));
         //List<IWebElement> tdList = trList[1].FindElements(tdTag).ToList();
         IJavaScriptExecutor js = driver as IJavaScriptExecutor;
        wait.Until(ExpectedConditions.ElementExists(By.XPath("/html/body/div[2]/section/form/div[2]/div/div/table/tbody/tr[1]/td[3]")));
        IWebElement hiddenElem = trList[0].FindElement(By.XPath("/html/body/div[2]/section/form/div[2]/div/div/table/tbody/tr[1]/td[3]"));

回答1:


Selenium simulates user actions. If the element is not visible and the user can't read it, Selenium can't read it as well. To avoid this problem we can use the WebElement attributes.

IList<IWebElement> hiddenElements = driver.FindElements(By.CssSelector(".k-master-row > [style=display:none]"));
string text = hiddenElements[1].GetAttribute("textContent");

You should have the two hidden elements in the list. Just access the second by index and get the text.



来源:https://stackoverflow.com/questions/35008101/how-can-i-get-displaynone-element-using-selenium-webdriver-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!