Jetz
Jetz

Reputation: 255

How to handle automatically generated web element (id)

I can't find element, because every time I refresh page, the element id is changed automatically

enter image description here

after refresh "input-19" is changed to any other, such as "input-2566"

how to handle these changes in selenium? to find elements..

P.S. there is about ~20 checkbox'es with a same element. Differs only number after input.

enter image description here

Upvotes: 1

Views: 362

Answers (2)

cruisepandey
cruisepandey

Reputation: 29382

Please use below xpath, with method contains

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

update :

You were missing (

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

Upvotes: 1

Andrey Kurkula
Andrey Kurkula

Reputation: 36

u can try something like that:

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
    })

use xpath, not element id

Upvotes: 0

Related Questions