如何处理自动生成的网页元素(id)

How to handle automatically generated web element (id)

找不到元素,因为每次刷新页面,元素id都会自动改变

刷新后“input-19”更改为任何其他,例如“input-2566”

如何处理硒的这些变化?查找元素..

P.S。大约有 20 个具有相同元素的复选框。输入后只有数字不同。

你可以试试这样的:

const button = await driver.wait(
      until.elementLocated(By.xpath('YOUR XPATH ELEMENT')), 15000).then(button => {
      return driver.wait(
        until.elementIsVisible(button),
        15000)}
        })
      button3.sendKeys('your text ').then(async function() {
      console.log(button.sendKeys,'input - done');
      return true
    })

使用 xpath,而不是元素 id

请使用下面的 xpath,方法 contains

//label[contains(@for,'input') and contains(@class,'v-label theme--light')]

更新:

你不见了(

private static By checkboxSpecialist = By.xpath("(//label[contains(@for,'input') and contains(@class,'v-label theme--light')])[5]");