Find element by ID

Using the IDs is the easiest and safest way to locate an element in the HTML. If a web page is W3C HTML conformed, the IDs should be unique and identified in the web controls of the page.

In contrast to texts, IDs are less prone to change (e.g., developers may decide to change the label but are less likely to change the ID). We can do this by completing the following command.

driver.findElement(webdriver.By.id("submit_btn")).click();

Get hands-on with 1400+ tech skills courses.