I have to click on the button which has id. But this id is generated dynamically. And find By.className() is not doing anything.
The HTML code for the button:
<td class="x-btn-mc">
<em class="" unselectable="on">
<button id="cq-gen372" class=" x-btn-text" type="button">OK</button>
</em>
</td>
How to select the button and click on it in Java?
By.className()really was bugged in IE and some older Selenium versions. I didn’t know it is still the case. Anyway! You can search by a lot of things, not just id:You can try
By.xpath("//button[text()='OK']");if it is the only (or the first) OK button on page.For more xpaths, see XPath v1.0 on w3.org and XPath v2.0 on w3.org – only for some new browsers!.
Or you can go with css selectors – The w3 again or wikipedia.