Home > Blockchain >  Java Selenium FindBy cannot find div by unique class name
Java Selenium FindBy cannot find div by unique class name

Time:01-03

I am using Selenium with Java and I have encountered issue that I am unable to find div by class name, even though it is unique:

<div ></div>

I am able to find any other element, e.g. input, button, etc. I have issues with div tag only.

I have tried getting this web element using either @FindBy() annotation and findElement() method:

driver.findElement(By.className("123123-randomclassname")) driver.findElement(By.cssSelector("div[class='123123-randomclassname'"))

@FindBy(className = "123123-randomclassname") @FindBy(css = "div[class='123123-randomclassname'")

Any of these solutions did not work and I couldn't find element.

CodePudding user response:

Try with following css selector

driver.findElement(By.cssSelector("div[class^='123123-']"))

CodePudding user response:

//@ and ]closing bracket was missing in syntax
WebElement DivTag = driver.findElement(By.xpath("div[@class='123123-randomclassname']")); //OR
@FindBy(xpath = "div[@class='123123-randomclassname']") WebElement DivTag2;

  • Related