How to make Selenium click a dynamically generated button?

Asked

Viewed 125 times

1

I need the bot to make a confirmation by clicking this button, which appears in a popup:

<button class="btn btn-info" id="c2e9772d-375d-47a1-9088-da9824d2e856">Sim</button>

But the button in question seems to be generated dynamically as it has a different ID for each transaction. This is the mapping I made:

driver.FindElement(By.Id("ce5597d1-6023-4e63-b3e9-ec2eb4475370")).Click();

Is there another way to make the bot find this button? By the text, for example? Or even by having the bot click on a specific window coordinate?

  • If it is always rendered in the same place, take it by xpath, go to the html code of the site, right click on the html button, then on copy -> xpath. Then call it the xpath -> driver.Findelement(By.Xpath("xpath here")). Click();

  • 1

    It worked perfectly! Just one detail: I used copy -> copy full Xpath. With Xpath copy I could not solve

  • I published as an answer there then. flwww

1 answer

0

If it is always rendered in the same place, take it by xpath, go to the html code of the site, right click on the html button, then on copy -> full copy Xpath. Then call him by the xpath

driver.FindElement(By.XPath("xpath aqui ")).Click(); 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.