简体   繁体   English

无法使用 Selenium/c# 单击 Dynamics365 下拉菜单 - “ElementNotVisibleException”

[英]Unable to click on Dynamics365 drop down menu using Selenium/c# - “ElementNotVisibleException”

I'm automating Dynamics365 CRM using Selenium/C#.我正在使用 Selenium/C# 自动化 Dynamics365 CRM。 Able to click and drop the menu, but unable to find and click on the "Submitted" option (line 2 code).能够单击并下拉菜单,但无法找到并单击“提交”选项(第 2 行代码)。 Getting this exception: OpenQA.Selenium.ElementNotVisibleException: '// [contains(text(),'Submitted')]'*.出现此异常: OpenQA.Selenium.ElementNotVisibleException: '// [contains(text(),'Submitted')]'*。 Appreciate any ideas how to handle this issue.感谢任何想法如何处理这个问题。 Also I've given the gui and html below.我还在下面给出了 gui 和 html。 Highlighted in last picture is the field where drop down is.最后一张图片中突出显示的是下拉框所在的字段。

使用的功能 在此处输入图像描述 在此处输入图像描述

Automating/scraping Dynamics 365 on the WEB UI side can be difficult, I have been there.在 WEB UI 端自动化/抓取 Dynamics 365 可能很困难,我去过那里。 The UI form uses a lot of JS event handling, css class naming to show/hide values, boxes etc.. By relying on just calling "click" event on elements, i'm sure will be difficult if not impossible for you to reach your goals. UI 表单使用了大量的 JS 事件处理,css class 命名来显示/隐藏值、框等。仅依靠在元素上调用“单击”事件,我敢肯定,如果不是不可能的话,你会很难达到你的目标。 For instance, the elements are sometimes sensitive to mouse hover and click events, at the same time?例如,元素有时同时对鼠标 hover点击事件敏感? Are you able to interface with local js objects?.你能与本地 js 对象交互吗? Because there is a way easier way.因为有一种更简单的方法。 Dynamics 365 uses a local js Form API called Xrm so google that: Here is an example of getting list of attributes available on the form. Dynamics 365 使用名为 Xrm 的本地 js 表单 API,因此谷歌表示:这是获取表单上可用属性列表的示例。 Run this in browser console.在浏览器控制台中运行它。

Xrm.Page.getAttribute()

It will return a list of attribute names.它将返回属性名称列表。 Find the attribute name that corresponds to you dropdown field.找到与您的下拉字段对应的属性名称。 To get a list of available option values (key/value pair) you can simple do:要获取可用选项值(键/值对)的列表,您可以简单地执行以下操作:

Xrm.Page.getAttribute("industrycode").getOptions()
// industrycode in this example is a standard attribute of account entity
// returns [{ name: <string>, value: <int>  }, {...} ]

Find the correct value and set the field like so:找到正确的值并像这样设置字段:

Xrm.Page.getAttribute("industrycode").setValue([value])

Then save the form.然后保存表格。

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

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