Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium Selnium元素文本值,其中文本()实际正在查找By对象_Selenium - Fatal编程技术网

Selenium Selnium元素文本值,其中文本()实际正在查找By对象

Selenium Selnium元素文本值,其中文本()实际正在查找By对象,selenium,Selenium,请考虑以下代码: By byCheckAll = By.XPath("//span[text()='Check all']"); IWebElement thingy = BrowserWindow.Instance.Driver.FindElement(byCheckAll); 在对问题进行故障排除时,我注意到thingy元素的Text属性是空字符串: 我正在研究为什么元素不可交互,并注意到这一点,所以我想知道到底找到了什么元素 我不知道如何通过文本查找元

请考虑以下代码:

        By byCheckAll = By.XPath("//span[text()='Check all']"); 
        IWebElement thingy = BrowserWindow.Instance.Driver.FindElement(byCheckAll);
在对问题进行故障排除时,我注意到thingy元素的Text属性是空字符串:

我正在研究为什么元素不可交互,并注意到这一点,所以我想知道到底找到了什么元素

我不知道如何通过文本查找元素、不接收错误以及文本为空。请解释一下。谢谢

编辑:很难确定有多少代码/信息与问题相关。因此,我在评论中加入了这一点

所讨论的方法是:

        public void CheckAll()
    {
        ClickButtonToDrop();
        By byRootDiv = By.XPath("//div[starts-with(@class, 'ui-multiselect-menu')]");
        var webElements = BrowserWindow.Instance.Driver.FindElements(byRootDiv);
        IWebElement rootElement = null;
        foreach (var webElement in webElements)
        {
            if (webElement.Displayed)
            {
                rootElement = webElement;
                BrowserWindow.Instance.HighlightElement(webElement);

            }

        }


        Element clickAllLink = new Element(rootElement, By.ClassName("ui-multiselect-all"));
        //By byCheckAll = By.XPath("//span[text()='Check All']/parent::div[@tag='a']"); // get the span, then the parent link
        By byCheckAll = By.XPath("//span[text()='Check all']"); // get the span, then the parent link
        IWebElement thingy = rootElement.FindElement(byCheckAll);

        //clickAllLink.Highlight();
        //clickAllLink.Click();

    }
rootElement是IWebElement thingy所在的div

突出显示的DIV的HTML是

  • 全部选中
  • 全部取消选中
  • 访问签入 与Chrome开发者工具中显示的HTML相同,带有突出显示的div(上述代码中的突出显示方法)


    在设置thingy对象的地方没有抛出错误,也就是我的断点所在的地方,我已经设置了一个断点,以获得watch window屏幕截图中的信息

    您可以指定要刮取的页面吗?请添加或提供指向整个HTML的链接。屏幕截图显示文本为空,因此您需要更改xpath以不使用text@AdrianJimenez,她说的是选择器使用文本搜索查找不包含文本的元素。她想知道XPath搜索如何返回不包含文本的元素。无论如何,您需要提供完整的代码、html以及在执行代码时出现的任何错误,感谢您指定要删除的页面?请添加或提供指向整个html的链接屏幕截图显示文本为空,因此您需要更改XPath,不用text@AdrianJimenez,她说的是选择器使用文本搜索查找不包含文本的元素。她想知道XPath搜索如何返回不包含文本的元素。无论如何,您需要提供完整的代码、html以及在执行代码时遇到的任何错误,谢谢