简体   繁体   English

Selenium Webdriver C#-无法在使用角度UI开发的网格中找到元素

[英]Selenium webdriver C# - Unable to find the element in a grid developed using angular UI

I am trying to automate a web application developed using angular JS through selenium webdriver(C#) and in that i am trying to click on a cell in a angular UI grid, i tried finding by css selector or xpath but it didn't help. 我试图通过selenium webdriver(C#)自动化使用selenium webdriver(C#) JS开发的Web应用程序,并且我试图单击有角度的UI网格中的单元格,我尝试通过CSS选择器或xpath查找,但没有帮助。

Css selector is generating dynamic ID - #\31 460691734316-0-uiGrid-00KQ-cell > div

Xpath is also dynamic //*[@id="1460691734316-0-uiGrid-00KQ-cell"]/div

and i tried using 我尝试使用

driver.FindElements(By.CssSelector("*[id^='1460'][id$='cell']"));

but it didn't help 但这没有帮助

any help will be highly appreciated. 任何帮助将不胜感激。 I can send more details if needed 如果需要,我可以发送更多详细信息

For my particular problem with the HTML page containing iframes and developed with AnglularJS the following trick saved me a lot of time: In the DOM I clearly saw that there is an iframe which wraps all the content. 对于我的包含iframe并使用AnglularJS开发的HTML页面的特殊问题,以下技巧为我节省了很多时间:在DOM中,我清楚地看到有一个iframe可以包装所有内容。 So following code supposed to work: 所以下面的代码应该工作:

driver.switchTo().frame(0);
waitUntilVisibleByXPath("//h2[contains(text(), 'Creative chooser')]");

But it was not working and told me something like "Cannot switch to frame. Window was closed". 但是它没有用,并告诉我“无法切换到框架。窗口已关闭”之类的信息。 Then I modified the code to: 然后,我将代码修改为:

driver.switchTo().defaultContent();
driver.switchTo().frame(0);
waitUntilVisibleByXPath("//h2[contains(text(), 'Creative chooser')]");

After this everything went smoothly. 在此之后,一切顺利。 So evidently Angular was mangling something with iframes and just after loading the page when you expect that driver is focused on default content it was focused by some already removed by Angular frame. 因此,显然Angular正在使用iframe进行处理,并且在加载页面之后,当您期望驱动程序专注于默认内容时,Angular框架已将其删除了。 Hope this may help some of you. 希望对您有所帮助。

What about trying to find the element with Selenium IDE which is a plugin of firefox ? 尝试使用Selenium IDE(firefox的插件)查找元素怎么办?

In the IDE, you can easily find the selector using selecting the element with GUI 在IDE中,可以通过使用GUI选择元素来轻松找到选择器

Rather than identifying the element specifically by its ID, could you use the elements around it instead? 您可以使用周围的元素代替它,而不是通过其ID专门标识该元素? Is this cell within a table and at a consistent position? 该单元格是否在表格中并且位于一致的位置? Is there a parent element you could more consistently select and iterate through the children in your C# program to identify the appropriate cell you're looking for? 是否有一个父元素可以更一致地选择并遍历C#程序中的子元素,以标识所需的合适单元格?

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

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