RSelenium中的下拉框 [英] dropdown boxes in RSelenium

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

问题描述

如何与RSelenium中的下拉框进行交互?特别是,我可以使用findElement选择下拉框,但是如何选择它呢?

How can one interact with dropdown boxes in RSelenium? In particular, I can select the dropdown box using findElement but how does one select an option with it?

推荐答案

此处是基于xpath选择下拉列表的代码.

here is the code to select a drop down list based on xpath.

由于下拉列表位于iframe内部,因此我必须先切换到该iframe. 在您的情况下,这可能会容易得多.

Since the dropdown is inside an iframe, I have to switch into that iframe first. It probably is much easier in your situation.

RSelenium的新手,请查看快速入门指南,要详细了解该功能,请参阅pdf 文档.

New to RSelenium, check out the quick start tutorial, want to learn more about the function, refer to the pdf documentation.

require(RSelenium)
remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4444, browserName = "firefox")

remDr$open()
remDr$navigate("http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select")

iframe <- remDr$findElement(using='id', value="iframeResult")
remDr$switchToFrame(iframe)

# change audi to whatever your option value is
option <- remDr$findElement(using = 'xpath', "//*/option[@value = 'audi']")
option$clickElement()

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

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