user3012605
user3012605

Reputation: 13

Is it possible to enter a text in a textbox without specific Element ID

Im doing a test that enter text in the textbox but it dont have specific ID so everytime i run the test it will change. im using selenium webdriver in java please help

Upvotes: 1

Views: 567

Answers (2)

Abhishek Singh
Abhishek Singh

Reputation: 10229

The following can work. You can google for them and see how they work.

driver.findElement(By.id("id"));
driver.findElement(By.cssSelector("cssSelector"));
driver.findElement(By.name("name"));
driver.findElement(By.linkText("linkText"));
driver.findElement(By.partialLinkText("partialLinkText"));
driver.findElement(By.className("className"));
driver.findElement(By.xpath("xpath"));

I am sure some of them will be useful. Please let me know if you want more info. The easiness of using them is in the order which i have mentioned.

Upvotes: 2

Petr Mensik
Petr Mensik

Reputation: 27496

What means doesn't have a specific ID?If id at least partially remains the same you can use the CSS locator

driver.findElement(By.cssLocator("input[id*=somePartWhichNotChange]"));
//* star means contains

if not, then you can use cssSelector to get to your element like "body table input" or use xpath as a last resort.

Upvotes: 1

Related Questions