【问题标题】: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我试图找到这个按钮,每个玩家都有一个单独的按钮。有没有我可以用来调用每个玩家的代码,可以互换
【发布时间】:2021-10-20 05:46:46
【问题描述】:

这是 2 个播放器 HTML 源代码的示例

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

【问题讨论】:

标签: python html selenium selenium-webdriver selenium-chromedriver


【解决方案1】:

为什么不是这样的 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()

其他按钮以此类推。

【讨论】:

    猜你喜欢
    • 2019-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-06
    • 2011-07-28
    • 1970-01-01
    • 2021-06-19
    相关资源
    最近更新 更多