请单击当前位置

2024-03-29 05:57:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个下拉菜单,我需要点击激活。下拉列表的元素不会在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元素

这是一张照片: enter image description here


Tags: fromimportsend元素列表htmlseleniumcommon
1条回答
网友
1楼 · 发布于 2024-03-29 05:57:02

我在回答我自己的问题,以防其他人发现自己处于这种情况,并准备将笔记本电脑扔出窗外

不要为点击而烦恼。使用“回车”

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)
nextButton.send_keys(Keys.ENTER)

相关问题 更多 >