【发布时间】:2020-12-01 17:11:01
【问题描述】:
我有一个下拉菜单,我需要单击它来激活。下拉列表的元素没有暴露在html中,因此无法找到点击。因此,一旦激活了下拉菜单,我就会选择我想要的选项,现在我只需要在该位置单击鼠标,但我不知道该怎么做。
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains as AC
from selenium.webdriver.common.keys import Keys
nextButton = browser.find_element_by_xpath('//*[@id="rendererColorClassifyMethodDropdown"]')
nextButton.click()
nextButton.send_keys(Keys.ARROW_UP)
nextButton.send_keys(Keys.ARROW_UP)
nextButton.send_keys(Keys.ARROW_UP)
nextButton.send_keys(Keys.ARROW_UP)
nextButton.send_keys(Keys.ARROW_UP)
AC.click()
这会导致这个错误:
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: click() missing 1 required positional argument: 'self'
向上滚动正在工作,因为我可以看到监视 python 命令,但是一旦我在那里就无法单击该选项。使用 nextButton.click() 只会重置下拉菜单。
这是点击后调用下拉菜单的 html:
<input class="dijitReset dijitInputInner" type="text" autocomplete="off" data-dojo-attach-point="textbox,focusNode" role="textbox" aria-autocomplete="both" aria-required="true" tabindex="0" id="rendererColorClassifyMethodDropdown" value="" aria-invalid="false" readonly="" style="cursor: pointer;">
紧随其后的标签是:
<input type="hidden" value="Natural Breaks">
当我使用箭头键滚动时,第二个标签的值会更改为当前滚动值的任何值,但无法在实际下拉显示中找到可点击值的 html 元素。
【问题讨论】:
-
下拉列表的元素没有暴露在html中,因此找不到点击。什么意思?否则如何与它们互动?
-
这是一个奇怪的 dijit 属性。我为下拉菜单添加了 html 标记以及它显示为当前值的内容。 html 中没有显示我可以看到的值的列表。
-
没关系。我可以使用我发现的回车。