Nagarjuna Reddy
Nagarjuna Reddy

Reputation: 819

Need to get the tool tip text from the active span element located inside another span in selenium

In this application, there is an option to activate or deactivate a channel.

When this channel is activated, span containing tool tip to deactivate is activated like shown below. chanel activated

Similarly, When this channel is de-activated, span containing tool tip to activate is activated like shown below.

channel de-activated

If I can figure out the xpath to active span I would be able to verify this element. BUt having hard time to find the xpath to active span.

</span>
                                      <span id="stat965"> 
                                            <span class="btn btn-small deactivateBtn btn-warning" href="javascript:void(0);" data-toggle="tooltip" onclick="status('ZVJxWHlYYUhMaWxZM2xqT1A2YTdydz09' ,'false','TWITTER',965);" title="" data-original-title="Deactivate">
                                                <i class="fa fa-times"></i>
                                            </span>
                                            <span class="btn btn-small activateBtn btn-primary" data-toggle="tooltip" style="display: none;" href="javascript:void(0);" onclick="status('ZVJxWHlYYUhMaWxZM2xqT1A2YTdydz09' ,'true','TWITTER',965);" title="" border="0" data-original-title="Activate"> <i class="fa fa-check"></i>
                                            </span>

                                    </span>

code for validation

Upvotes: 2

Views: 582

Answers (4)

Naveen Kumar R B
Naveen Kumar R B

Reputation: 6398

Use isDisplayed method on following web elements which tell whether that element is visible on the web page or not.

try for Deactivate span tag with following XPATH:

//span[@style="display: inline-block;"  and @data-original-title="Deactivate"]

returns WebElement only if Deactivate span tag is active otherwise null, so you can check for Activate span tag.

for Activate span tag with following XPATH:

//span[@style="display: inline-block;"  and @data-original-title="Activate"]

Upvotes: 2

noor
noor

Reputation: 3004

if you want to find the deactive span, use the below cssSelector:

span[class*="deactivateBtn"]

for choosing deactivate span, use the below cssSelector:

span[class*="activateBtn"]

hope this helps and let me know what is the result.

Upvotes: 0

Rajkumar
Rajkumar

Reputation: 58

According to you, only one element (span) should be active. Right? If yes, you can use enabled method. Enabled method will return true if element is enabled. As per your need, you can process the return value. Example:

  if(driver.findelement(By.xpath("//span[@data-original-title="Deactivate"]).enabled)
{
// do your actions
}

And check the same for activate element and continue your steps as per your need.

Upvotes: 0

Mouli
Mouli

Reputation: 299

Please try the below CSS for to identify Activate :

span.activateBtn

Please try the below CSS for to identify De-Activate :

span.deactivateBtn

Upvotes: 0

Related Questions