문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top