简体   繁体   English

使用 Selenium 进行编程以使用 c# 和 Visual Studio 2019 自动化 ARIA:Listbox

[英]Programming with Selenium to automate an ARIA:Listbox with c# and Visual Studio 2019

I am trying to automate a download function from a broker.我正在尝试从代理自动下载 function。 I have been able to logon with id and pw, navigate to specific web pages, and select and collect items from the site.我已经能够使用 id 和 pw 登录,导航到特定的 web 页面和 select 并从该站点收集项目。 I am stumped, however, on how to select an ARIA:Listbox item in an embedded form.但是,我很难理解如何以嵌入式形式 select ARIA:Listbox 项目。 All the examples I have seen show windows forms listbox or HTML select lists which is not the way this www site is built.我见过的所有示例都显示 windows forms 列表框或 HTML Z99938282F04071859941ECF18F16 列出了这个 www 站点的方式。

I have been successful with the c# Selenium findelement By.ID for the listbox required, but the last error said it must be scrolled into view.我已经成功使用 c# Selenium findelement By.ID 获取所需的列表框,但最后一个错误说它必须滚动到视图中。 I'm guessing that the item is not in view because I haven't got the ARIA Listbox click to work to display the list.我猜该项目不在视图中,因为我没有点击 ARIA 列表框来显示列表。 I've tried clicking on the dropdown arrow, and on the cell itself but the list doesn't show up.我尝试单击下拉箭头和单元格本身,但列表未显示。

I need some pointers on what to try next.我需要一些关于下一步尝试的指示。

Thanks OK - here's some additional info: I apologize if this doesn't present right - I'm just learning to use the site...谢谢 好的-这里有一些附加信息:如果这不正确,我深表歉意-我只是在学习使用该网站...

When I use the program code当我使用程序代码时


browser_driver.FindElement(By.Name("OfxDownloadForm:downloadOption")).Click();

I get the message我收到消息

OpenQA.Selenium.ElementNotInteractableException: 'Element could not be scrolled into view' OpenQA.Selenium.ElementNotInteractableException:'元素无法滚动到视图中'

The relevant html follows:相关html如下:

<span id="OfxDownloadForm:downloadOption" role="presentation" onfocusjs="removingDuplicateContentFromMenu();;vg.validation.focus(this)" onchangejs="setWarnings('downloadOption');" onblurjs="vg.validation.blur(this)" class="vg-SelOneMenu" compname="selectOneMenu">
    <div class="vg-SelOneMenuCont vg-SelOneMenuNoWrap vg-SelOneMenuFocusText vg-SelOneMenuHover" id="OfxDownloadForm:downloadOption_cont" aria-owns="menu-OfxDownloadForm:downloadOption">
    <a href="javascript:void(0);" onclick="return false;" class="vg-SelOneMenuTrigger" id="OfxDownloadForm:downloadOption_aTag" role="button" aria-xpanded="false" aria-haspopup="true" aria-controls="menu-OfxDownloadForm:downloadOption" aria-labelledby="downLoadOptionText OfxDownloadForm:downloadOption_text" aria-disabled="false">

If I go after "OfxDownloadForm:downloadOption_aTag" with:如果我在“OfxDownloadForm:downloadOption_aTag”之后使用 go :

wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.PresenceOfAllElementsLocatedBy(By.ID("OfxDownloadForm:downloadOption_aTag")));
browser_driver.FindElement(By.ID("OfxDownloadForm:downloadOption_aTag")).Click();  

Nothing happens - the popup doesn't occur.什么都没有发生 - 弹出窗口没有发生。

Hope this comes out ok!希望这一切顺利!

After much research and reading, I figured out that I had to do a two step action in the program:经过大量研究和阅读,我发现我必须在程序中执行两步操作:

input_element = browser_driver.FindElement(By.Id("OfxDownloadForm:downloadOption_aTag"));
    Actions actions = new Actions(browser_driver);
    actions.MoveToElement(input_element);
    actions.Perform();
    input_element.Click();

I believe the FindElement method just located the element, but didn't reposition the mouse into the document on that element.我相信 FindElement 方法只是定位了元素,但没有将鼠标重新定位到该元素上的文档中。 MoveToElement method scrolled down the document and brought the element into the view, and then a click on the same element allowed the drop-down listbox to do its processing. MoveToElement 方法向下滚动文档并将元素带入视图,然后单击同一元素允许下拉列表框进行处理。 Once I did the find and the move, I was able to select the appropriate dropdown item.一旦我找到并移动,我就能够 select 适当的下拉项目。

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

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