I'm writing some Selenium tests in Java and will later need to find elements by DOM attributes that are not visible in the html. The code below attempts to find the search bar in google using the "class" attribute and then the DOM attribute "checked". Only the first of these works for me, the 2nd one fails with "Unable to locate element".
I assume that I'm either doing something wrong with the xpath or that I'm not understanding the DOM attributes correctly. I tried with several other attributes in the DOM but always get the same result. I also tried using cssSeletor instead of xpath, but again with the same results.
As indicated in the code I use Chrome (with Windows 7).
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class SeleniumTest {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\Drivers\\chromedriver.exe");
DesiredCapabilities caps = DesiredCapabilities.chrome();
WebDriver driver = new ChromeDriver(caps);
driver.manage().window().maximize();
driver.get("http://www.google.com");
WebElement elementByClass = driver.findElement(By.xpath("//input[@class='gsfi']"));
WebElement elementByDOM = driver.findElement(By.xpath("//input[@checked='false']"));
}
}
Edit: If I inspect the google searchbar with F12 dev tool I find the html:
<input spellcheck="false" dir="ltr" style="border: medium none; padding: 0px; margin: 0px; height: auto; width: 100%; background: transparent url("data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw%3D%3D") repeat scroll 0% 0%; position: absolute; z-index: 6; left: 0px; outline: medium none;" aria-autocomplete="both" role="combobox" aria-haspopup="false" class="gsfi" id="lst-ib" maxlength="2048" name="q" autocomplete="off" title="Søk" value="" aria-label="Søk" type="text">
If I inspect the DOM proprties of this element I can see the attribute "checked"=true. See image:

//input[@checked='false'], i don't find any element at all. Can you share the html code too?