sendkeystoelement执行,但在硒中未通过键

发布于 2025-02-09 00:19:34 字数 841 浏览 0 评论 0原文

我很难更改

2021/m-itf-tun-52a-2021/draws-and-results/“ rel =“ nofollow noreferrer”>此页面与R中的 不是两个选项的单独XPath(“单打”和“双打”)。在选项之间切换时,我可以看到唯一不同的是最终节点的内容。

因此,我尝试了另一种方法来(1)选择“下拉”,(2)输入我想要的选项,然后(3)单击Enter。但是,这是不起作用的,因为文本和击键都没有传递给网页。

library('RSelenium')
library('rvest')
library('tidyverse')
library('seleniumPipes') 

single.double.elem <- remDr$findElement(using = 'xpath', "//*[@class=' css-1hwfws3']") #find element
single.double.elem$clickElement() #click it
single.double.elem$sendKeysToElement(list("Doubles")) #attempt to type into box. This executes but the text is not passed to the box
single.double.elem$sendKeysToElement(list(key = "down_arrow")) #alternatively, attempt to go down to select Doubles option. This executes but nothing happens

我在这里做错了什么?我注意到,有些元素旁边有“ flex” - 这可能与它有关吗?

I am having difficulty changing the value of what appears to be a dropdown box (but I don't think is) on this page when interacting it with Selenium in R.

I don't think it's a dropdown because there are not separate xpaths for the 2 options ("Singles" and "Doubles"). When toggling between the options I can see that the only thing that differs is the content for the final node.

I have therefore tried a different method to (1) select the "dropdown", (2) type the option I want and then (3) click enter. However, this is not working because neither text nor keystrokes are being passed to the webpage.

library('RSelenium')
library('rvest')
library('tidyverse')
library('seleniumPipes') 

single.double.elem <- remDr$findElement(using = 'xpath', "//*[@class=' css-1hwfws3']") #find element
single.double.elem$clickElement() #click it
single.double.elem$sendKeysToElement(list("Doubles")) #attempt to type into box. This executes but the text is not passed to the box
single.double.elem$sendKeysToElement(list(key = "down_arrow")) #alternatively, attempt to go down to select Doubles option. This executes but nothing happens

What am I doing wrong here? I note that some elements have "flex" next to them - could this have anything to do with it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼中杀气 2025-02-16 00:19:34

确保在屏幕上可见下拉按钮,这应该像我一样工作:

# to click on Doubles dropdown
dropdownButton <- remdr$findElement(using = 'xpath', value = "//span[@class='icon']")$clickElement()
selectButton <- remdr$findElement(using = 'xpath', value = "//div[text()='Doubles']")$clickElement()

# to click on Singles dropdown
dropdownButton <- remdr$findElement(using = 'xpath', value = "//span[@class='icon']")$clickElement()
selectButton <- remdr$findElement(using = 'xpath', value = "//div[text()='Singles']")$clickElement()

Make sure the drop down button is visible on the screen and this should work as it did for me:

# to click on Doubles dropdown
dropdownButton <- remdr$findElement(using = 'xpath', value = "//span[@class='icon']")$clickElement()
selectButton <- remdr$findElement(using = 'xpath', value = "//div[text()='Doubles']")$clickElement()

# to click on Singles dropdown
dropdownButton <- remdr$findElement(using = 'xpath', value = "//span[@class='icon']")$clickElement()
selectButton <- remdr$findElement(using = 'xpath', value = "//div[text()='Singles']")$clickElement()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文