我试图找到这个按钮,每个玩家都有一个单独的按钮。有没有我可以用来召唤每个可以互换的玩家的代码

Im trying to find this button and there is a seperate one for each player. Is there a code i can use to call upon each player which is interchangeable

这是其中 2 位玩家的示例 HTML 来源

使用 python 和硒。如果你能给我一个代码来找到其中一个元素,我可能会找到一种方法来为任何给定的玩家改变它。谢谢

为什么这个 xpath 索引不是这样的:

(//span[@class='player-name'])[1]

或按钮:

//div[contains(@class, 'add-remove-player')]//button[contains(@class,'StyledIconButton')]

这将代表所有这些人。

如果您正在寻找第一个:

(//div[contains(@class, 'add-remove-player')]//button[contains(@class,'StyledIconButton')])[1]

第二个将是:

(//div[contains(@class, 'add-remove-player')]//button[contains(@class,'StyledIconButton')])[2]

等等..

在代码中:-

driver.find_element_by_xpath("(//div[contains(@class, 'add-remove-player')]//button[contains(@class,'StyledIconButton')])[1]").click()

其他按钮依此类推。