如何使用selenium访问<summary>标记

2024-04-19 20:14:10 发布

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

在这个网页上,有一个按钮,我需要按下。这是HTML源代码:

<summary aria-controls="dc_2" tabindex="0" role="button" aria-expanded="false"><span>The company I am travelling with is not listed</span>

我尝试使用span标记的XPATH访问它,但是它不起作用。有什么建议吗

这是我的代码:

span = '/html/body/main/section[2]/section/div[2]/form/details/summary/span'
driver.find_element_by_xpath(span).click()

1条回答
网友
1楼 · 发布于 2024-04-19 20:14:10

我不确定,必须使用开发工具查看页面,但这可能会起作用:

"/html/body/main/section[2]/section/div[2]/form/*[name()='details']/*[name()='summary']/span"

另外,强烈建议不要使用绝对XPath和绝对CSS选择器。他们非常不可靠

相关问题 更多 >