不能用 click() 一个带有 selenium 的 onclick 元素(试过文本 link、部分文本 link、xpath、css 选择器)

can't click() an onclick element with selenium (tried text link, partial text link, xpath, css selector)

我需要从这个 url 中删除一些数据: https://www.cnrtl.fr/definition/coupe

我需要废弃的 data/results 位于这 3 个不同的选项卡中:

我无法单击应该让我从一个选项卡切换到另一个选项卡的 onclick 元素。

这里是 3 个 onclick 元素之一的 html 代码:

3 个 onclick 元素之间的区别在于末尾的数字:

#COUPE1:
return sendRequest(5,'/definition/coupe//0');

#COUPE2:
return sendRequest(5,'/definition/coupe//1');

#COUPER:
return sendRequest(5,'/definition/coupe//2');

我试图通过 link 文本、部分 link 文本、xpath 和 css 选择器找到它们。

我关注了这个话题:

也试试 contains 和 text() 方法。

没有成功。

有几种方法可以做到这一点。我选择了我所做的方法,因为页面重新加载导致元素变得陈旧。

#Get the URL
driver.get("https://www.cnrtl.fr/definition/coupe")
#Find the parent element of the tabs
tabs = driver.find_element(By.ID, 'vtoolbar')
#Get all the list items under the parent (tabs)
lis = tabs.find_elements(By.TAG_NAME, 'li')
#loop over them (skipping the first tab, because that's already loaded)
for i in range(1, len(lis)):
    #Execute the same JS as the page would on click, using the index of the loop
    driver.execute_script(f"sendRequest(5,'/definition/coupe//{i}');")
    #Sleep to visualise the clicking
    time.sleep(3)