Search code examples
seleniumselenium-webdriverwebdriver

How to find webelement using style property


Below is the HTML code of an element and I want to locate this element by classs and style property using selenium webDriver in java

 <div class="qooxdoo-table-cell" style="left:252px;width:117px;height:24px;"/>

suggest a way which can be help full in selenium

I want to locate the element using java code i.e. Driver.findelement(by. ....


Solution

  • As long as the element isn't unique you must grab both attributes:

    This is the general form, replacing the empty strings for your required class and style:

    driver.findElement("By.xpath(//div[@class='' and style='']");
    

    So:

    driver.findElement(By.xpath("//div[@class='qooxdoo-table-cell' and style='left:252px;width:117px;height:24px;']");
    

    Best of luck!