Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top