Python 在不使用检查元素的情况下查找XPath?

Python 在不使用检查元素的情况下查找XPath?,python,selenium,xpath,Python,Selenium,Xpath,我正在做一个从气象机构自动下载数据的程序 问题是,为了使它更加独立,我尝试将Selenium to Tab键设置到某个位置,以便浏览器焦点可以“移动”到下载按钮。当我调用click()函数时,它什么都不做。因此,我尝试使用函数get_属性(“XPath”)提取XPath,但它返回None。如何提取XPath 我将把问题粘贴到这里: Bandera=driver.find_element_by_xpath('/html/body/div[2]/div[2]/div/div[3]/div/div/d

我正在做一个从气象机构自动下载数据的程序

问题是,为了使它更加独立,我尝试将Selenium to Tab键设置到某个位置,以便浏览器焦点可以“移动”到下载按钮。当我调用click()函数时,它什么都不做。因此,我尝试使用函数get_属性(“XPath”)提取XPath,但它返回
None
。如何提取XPath

我将把问题粘贴到这里:

Bandera=driver.find_element_by_xpath('/html/body/div[2]/div[2]/div/div[3]/div/div/div/div[1]/div/div/div[2]/div/table/tbody/tr[1]/td[1]/div/input')

Bandera.click()

Bandera.click()

## So Here i just select and dis-select a checkbox just to be near the Download button.

actions = ActionChains(driver)
actions.send_keys(Keys.TAB * 1 )
actions.perform()

#Here i just tabed to the button

Accion=driver.switch_to.active_element

#Maybe, here is when i lost the focus of the button?

Descarga_Actual=Accion.get_attribute("xpath")

谢谢,很抱歉占用您的时间。

要单击鼠标悬停,我将使用以下顺序:

your_dropdown_locator.click()
dropdown_option = driver.find_element_by_xpath("dropdown option locator")

actions = ActionChains(driver)
actions.move_to_element(dropdown_option)
actions.click().perform()
但是,这是通常用于下拉列表的方法。 使用:
driver。通过xpath('/html/body/div[2]/div[2]/div/div/div[3]/div/div/div[1]/div/div/div[2]/div/table/tbody/tr[1]/td[1]/div/input')查找元素。
这是代码的主要问题。 如果您粘贴了此下拉列表(或需要单击的按钮)的html代码,人们会帮助您找到更好的定位器。XPath/CSS必须是唯一的。在你的情况下,定位器是非常糟糕的

而且,我认为Bandera没有任何意义。单击两次()

在你的情况下,正如我所理解的,你只需要点击按钮。所以定位器是你的主要问题。 您需要找到正确的定位器,等待按钮可单击,然后单击它

您尝试执行的另一个问题是:


get\u attribute(“xpath”)
看起来对get\u attribute函数的工作方式的期望不正确。至少在此处检查此函数的含义

您看到答案了吗?