0

For this HTML:

<ul class="listnav" id="yui_3_16_0_1_1496654440419_3201" role="presentation"> 
 <li class="compose hasmultimsg primary-property-btn selected" id="Compose" role="presentation" data-fid="Compose"> 
  <button tabindex="0" title="Compose" class="btn btn-compose" id="yui_3_16_0_1_1496654440419_3200" data-action="compose"> 
    <i></i>
   <span class="icon-text" id="yui_3_16_0_1_1496654440419_3199">Compose</span> 
 </button> 
</li> 
</ul>

I want to retrieve the ID attribute of 'Compose' button.

Here is my code:

By btnBy = By.xpath("//div[@id = 'shellnavigation']/div/ul/li[@id = 'Compose']/button[@class='btn btn-compose']");
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(btnBy));

WebElement btnCompose = driver.findElement(By.xpath("//div[@id = 'shellnavigation']/div/ul/li[@id = 'Compose']/button[@class='btn btn-compose']"));
System.out.println("Text is : " + btnCompose.getText()
                + " Class is: " + btnCompose.getAttribute("class")
                + " Id is: " + btnCompose.getAttribute("id")
                + " Title is : " + btnCompose.getAttribute("title")
                + "innerHTML " + btnCompose.getAttribute("innerHTML"));

My setup method is:

@Before
public void setUp() throws Exception {
    try {
        if (driver != null)
            driver.quit();
        else {
            driver = new HtmlUnitDriver();
            driver.setJavascriptEnabled(true);
            driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
            java.util.logging.Logger.getLogger("com.gargoylesoftware")
                    .setLevel(Level.OFF);

            driver.manage().window().maximize();
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

I'm Using below configurations:

Windows 10,

Selenium Sever standalone 3.4.0,

HTML driver.

I'm seeing below output in console:

Text is : Compose Class is: btn btn-compose Id is: null Title is : Compose innerHTML <i class=""></i><span class="icon-text">Compose</span>

So the value for id attribute is null, the other attributes are OK.

I don't know why it's showing id null.

0 Answers0