RSelenium 从 Javascript 列表中选择下拉/组合框值 [英] RSelenium Select Dropdown/ComboBox Value from Javascript List

查看:25
本文介绍了RSelenium 从 Javascript 列表中选择下拉/组合框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 RSelenium 从网站下载 csv 文件.我进入了一个 Crystal Report Viewer 页面,然后选择导出按钮的元素并单击该按钮.然后会出现一个带有文件格式选择的导出窗口.我能够找到下拉列表的元素,但我遇到了列表值的问题.这些值似乎来自一个很长的 javascript 脚本,如下所示:

I am trying to download a csv file from a website using RSelenium. I get to the page, which is a Crystal Report Viewer, and select the element of the export button and click that button. Then an export window appears with a file format selection. I am able to find the element of the dropdown list but I am having issues with the values of the list. The values appear to be coming from a very long javascript script like the following:

<script type="text/javascript" language="JavaScript">
`{"args":`

{"args":{"id":"CrystalReportViewer_exportUI","availableFormats":[{"name":"Crystal Reports (RPT)","value":"CrystalReports"},{"name":"PDF","value":"PDF"},{"name":"Microsoft Excel (97-2003)","value":"MSExcel"},{"name":"Microsoft Excel (97-2003) Data-Only","value":"RecordToMSExcel"},{"name":"Microsoft Word (97-2003)","value":"MSWord"},{"name":"Microsoft Word (97)-2003) - Editable","value":"EditableRTF"},{"name":"Rich Text Format (RTF)","value":"RTF"},{"name":"Separated Values (CSV)","value":"CharacterSeparatedValues"},{"name":"XML","value":"XML"}]``</script>

下拉框如下所示:

我能够找到与上述下拉框相关的元素.

I am able to find the element related to the above dropdown box.

当我点击下拉菜单时,上面的列表会显示出来.当我在选择其中一个值时查看 HTML 元素时,我选择的值会在 HTML 代码中更新——我是从 Javascript 列表中假设的.单击分隔值 (CSV)"后如下所示:

When I click the dropdown menu the list above shows. When I am looking at the HTML element while selecting one of the values, the value I select gets updated in the HTML code--I'm assuming from the Javascript list. It looks like the following after I click "Seperated Values (CSV)":

<div id="id_name" class="icontext" style="white-space:nowrap;text-overflow:ellipsis;overflow:hidden;width:249px">分隔值 (CSV)<;/div>

我尝试使用以下代码但它不起作用:

I tried to use the following code but it does not work:

WebElemFileFormat <- remDr$findElement(using = 'id', "id_name")WebElemFileFormat$clickElement()WebElemFileFormat$sendKeysToElement(list("Separated Values (CSV)"))

我阅读了这篇文章选择一个 javascript 下拉菜单但不确定这如何转化为 RSelenium.非常感谢.

I read this post Selecting a javascript dropdown but not sure how that translates to RSelenium. Many thanks in advance.

推荐答案

在做了一些更多的研究之后,我决定走一条不同的道路.如果有人遇到类似的问题,我会留下这个.我注意到在使用下拉框后,我可以使用向下箭头或选项卡向下移动列表.

After doing some more research I decided to go a different route with this. I'll leave this up in case someone comes across a similar issue. I noticed that after playing around with the dropdown box I could use the down arrow or tab to moved down the list.

我使用以下代码来完成上面问题中我想要的:

I used the following code to complete what I wanted to in the question above:

`WebElemFileFormat <- remDr$findElement(using = 'id', "id_name")
remDr$setImplicitWaitTimeout(milliseconds = 10000)
WebElemFileFormat$clickElement()
remDr$sendKeysToActiveElement(list(key = 'tab'))
remDr$sendKeysToActiveElement(list(key = 'tab'))
remDr$sendKeysToActiveElement(list(key = 'tab'))
remDr$sendKeysToActiveElement(list(key = 'tab'))
remDr$sendKeysToActiveElement(list(key = 'tab'))
remDr$sendKeysToActiveElement(list(key = 'tab'))
remDr$sendKeysToActiveElement(list(key = 'tab'))
remDr$sendKeysToActiveElement(list(key = 'enter'))
`

请注意,我决定使用制表符而不是向下箭头.由于某种原因,向下箭头不起作用.我希望这对某人有所帮助!

Notice that I decided to use tab and not the down arrow. The down arrow was not working for some reason. I hope this helps someone!

这篇关于RSelenium 从 Javascript 列表中选择下拉/组合框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆