Psl
Psl

Reputation: 3920

select a button using selenium

how to select login button using selenium web driver

<li id="buttons" class="greetings_fmt">
    <a href="#">
       <div class="user_btn log_in_icon">LOG IN</div>
    </a>
    <a href="#">
       <div class="user_btn sign_up_icon">SIGN UP</div>
    </a>
</li>

tried with this code but not working

WebElement ele = driver.findElement(By.id("buttons"));
      List<WebElement> ele1 = ele.findElements(By.tagName("a"));
      for(WebElement e : ele1){         
         e.click()

      }

Upvotes: 0

Views: 51

Answers (2)

Monika
Monika

Reputation: 732

It looks what you are trying to automate is incomplete.Login is not a button. It is a link. Clicking on this link will take you nowhere as href="#".

Upvotes: 1

RNS
RNS

Reputation: 625

You can use following xpath for user case:

Xpath=//*[contains(text(),'LOG IN')]

Hope it will work for you.

Upvotes: 0

Related Questions