R - Rselenium - 使用 = 'id' 导航下拉菜单/列表/框 [英] R - Rselenium - navigate drop down menu / list / box using = 'id'
问题描述
如何通过"using = 'id' "(例如,remDr$findElement(using='id', value="main_ddYear")
导航动态下拉列表?
How can I navigate a dynamic drop down list via " using = 'id' " (e.g., remDr$findElement(using='id', value="main_ddYear")
?
我可以使用 findElement
找到并点击.单击后,我可以发送向下箭头"键(击键)和输入",如果我知道我的目标选择向下有多少箭头.
I can find and click using findElement
. After clicking I could send "down arrow" keys (keystrokes) and an "enter" if I know how many arrows down my targeted selection is.
页面源码示例
<select name="main$ddYear" onchange="javascript:setTimeout('__doPostBack('main$ddYear','')', 0)" id="main_ddYear" class="groupTextBox">
<option selected="selected" value="2017">2017</option>
<option value="2016">2016</option>
<option value="2015">2015</option>
<option value="2014">2014</option>
<option value="2013">2013</option>
</select>
我想做一些类似于这篇文章中的解决方案,但带有id"' 而不是 'xpath' .我无法适应 xpath 解决方案.
I would like to do something similar to the solution in this post but with 'id' instead of 'xpath' . I could not adapt the xpath solution.
另一个解决方案在 Java 中使用了我没有找到的Select"类在 quick 中引用开始教程或文档.
Another solution in Java used a "Select" class which I did not find referenced in the quick start tutorial or documentation.
我将发布一个单独的问题,关于如何抓取选项/值的下拉列表.
I will post a separate question about how to scrape the drop down list of options / values.
推荐答案
在对 XPath 有一点了解的情况下,调整使用 XPath 的链接解决方案应该很简单,例如:
With a little knowledge about XPath, adapting the linked solution which using XPath for your case should be straightforward, for example :
option <- remDr$findElement(using = 'xpath', "//select[@id='main_ddYear']/option[@value='2014']")
option$clickElement()
XPath 的简要说明:
//select[@id='main_ddYear']
:在 HTML 中的任意位置查找元素,其中
id
属性值等于'main_ddYear'
/option[@value = '2014']
:从这样的元素,返回子
其中
value
属性值等于'2014'
.
//select[@id='main_ddYear']
: Find<select>
element, anywhere in the HTML, whereid
attribute value equals'main_ddYear'
/option[@value = '2014']
: From such<select>
element, return child<option>
wherevalue
attribute value equals'2014'
.
这篇关于R - Rselenium - 使用 = 'id' 导航下拉菜单/列表/框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!