如何使用xpath获取onclick的价值?

Pau*_* YC 1 python selenium xpath

我有这段Html:

<tr class="selectable" onclick="PesquisarProntuarioView.EditarProntuario('108077098085')">
Run Code Online (Sandbox Code Playgroud)

我想获得 onclick 中的内容,我正在寻找一个可以给我的命令:

"PesquisarProntuarioView.EditarProntuario('01048108077098085')"
Run Code Online (Sandbox Code Playgroud)

我已经尝试过几个这样的命令:

element=driver.find_element_by_xpath("//a/tr/@onlick=PesquisarProntuarioView.EditarProntuario(*)")

driver.get(element)
Run Code Online (Sandbox Code Playgroud)

但是仍然没有线索,有人可以帮助我使用 Selenium/Python 中的相应命令吗?

ale*_*cxe 5

定位元素并使用get_attribute()方法

element = driver.find_element_by_xpath("//a/tr")
print(element.get_attribute("onclick"))
Run Code Online (Sandbox Code Playgroud)

如果您需要提取多个元素onclick,请使用find_elements_*并调用get_attribute()找到的每个元素:

for element in driver.find_elements_by_xpath("//a/tr"):
    print(element.get_attribute("onclick"))
Run Code Online (Sandbox Code Playgroud)