[英]RSelenium Select Dropdown/ComboBox Value from Javascript List
I am trying to download a csv file from a website using RSelenium. 我正在尝试使用RSelenium从网站下载csv文件。 I get to the page, which is a Crystal Report Viewer, and select the element of the export button and click that button.
我进入页面,这是一个Crystal Report Viewer,并选择导出按钮的元素,然后单击该按钮。 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:
这些值似乎来自一个非常长的javascript脚本,如下所示:
<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>
The dropdown box looks like the following: 下拉框如下所示:
I am able to find the element related to the above dropdown box.
我能够找到与上面的下拉框相关的元素。
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.
当我在选择其中一个值时查看HTML元素时,我选择的值会在HTML代码中更新 - 我从Javascript列表中假设。 It looks like the following after I click "Seperated Values (CSV)":
单击“分隔值(CSV)”后,它看起来如下所示:
<div id="id_name" class="icontext" style="white-space:nowrap;text-overflow:ellipsis;overflow:hidden;width:249px">Separated Values (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)"))
I read this post Selecting a javascript dropdown but not sure how that translates to RSelenium. 我读了这篇文章选择一个javascript下拉列表但不确定如何转换为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. 请注意,我决定使用tab而不是向下箭头。 The down arrow was not working for some reason.
由于某种原因,向下箭头无效。 I hope this helps someone!
我希望这可以帮助别人!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.