简体   繁体   English

硒-driver.find_element_by_css_selector找不到元素(C#)

[英]Selenium - driver.find_element_by_css_selector can't find the element (c#)

I'm trying to get selenium to click on a selection in a tree however I'm not getting anywhere. 我试图让硒单击树中的选择,但是我什么也没得到。

Could anyone help: 任何人都可以帮助:

在此处输入图片说明

The code i'm using is as follows: 我使用的代码如下:

Actions act = new Actions(driver);
act.DoubleClick(driver.FindElement(By.CssSelector("#reportsTree_tv_active > div.k-bot > span.k-in > div.menu-security-item > div.menu-security-label"))).Build().Perform();

Actually your selector is correct. 实际上您的选择器是正确的。 You can simplify it to 您可以简化为

"li#reportsTree_tv_active div.menu-security-label"

I think you get the correct element. 我认为您了解正确的要素。 Maybe the double click doesn't do what you need. 双击可能无法满足您的需求。 If element couldn't be located, you would get OpenQA.Selenium.NoSuchElementException . 如果找不到元素,则将获得OpenQA.Selenium.NoSuchElementException Try getting an element like this: 尝试获取如下所示的元素:

var element = driver.FindElement(By.CssSelector("li#reportsTree_tv_active div.menu-security-label");

And then check if its Text is "Worksheets" 然后检查其Text是否为"Worksheets"

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

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