Renata Barros
Renata Barros

Reputation: 41

How to click on a tab with specific text?

I need to click on tab "Pis/Cofins" in my application

<ul class="nav nav-tabs" id="tabs">
    <li class="">
        <a href="#dados" aria-controls="home" data-toggle="tab" aria-expanded="false">Dados Gerais</a>
    </li>
    <li class="active">
        <a href="#pisCofins" data-toggle="tab" aria-expanded="true">Pis/Cofins</a>
    </li>
    <li>
        <a href="#combustivel" data-toggle="tab">Combustíveis</a>
    </li>
    <li>
        <a href="#modoDeServir" data-toggle="tab">Modo de Servir</a>
    </li>
    <li>
        <a href="#imagens" data-toggle="tab">Imagens</a>
    </li>
    <li>
        <a href="#informacoes" data-toggle="tab">Informações</a>
    </li>
</ul>

Upvotes: 0

Views: 1318

Answers (2)

undetected Selenium
undetected Selenium

Reputation: 193128

As per the HTML you have shared to click on tab with text as Pis/Cofins you can use either of the following solutions:

  • LinkText:

    driver.FindElement(By.LinkText("Pis/Cofins")).Click();
    
  • CssSelector:

    driver.FindElement(By.CssSelector("ul.nav.nav-tabs#tabs a[href$='pisCofins']")).Click();
    
  • XPath:

    driver.FindElement(By.XPath("//a[contains(@href,'pisCofins') and contains(.,'Pis/Cofins')]")).Click();
    

Upvotes: 2

BountyHunter
BountyHunter

Reputation: 1411

You may simply use the following xpath:

//a[text()='Pis/Cofins']

You may use extension like Firebug in firefox to easily find locators and use them in your test scripts

Upvotes: 2

Related Questions