user2340124
user2340124

Reputation: 111

Not able to find get the text in browser

<!DOCTYPE html>
<html lang="en">
<head>
<body class="layout-two-column unibet uMyAccount">
<div class="tooltip-container">
<div id="tooltip" class="tooltip tooltip-error right-center" style="top: 466px;     left:           709px; display: none;">
       <div class="tooltip-content gutter-3 icon icon-small icon-error">DANISH SITE                SPECIFIC</div>
     <div class="tooltip-pointer"></div>
     <div class="tooltip-pointer-decoration"></div>
 </div>
 </div>

 <div id="window">
 <div id="container" class="lobby-theme-3">
 <header id="header">
 <nav id="nav-main">
 <div id="no-sub-nav"></div>
 <div id="main" role="main">
 <div class="stack-wrap gutter-col-wrap-2">

Tried the following to get the text "DANISH SITE SPECIFIC":

//body[contains(@class,'layout-two-column unibet uMyAccount')]//div[contains(@id,'tooltip')]//div[contains(@class,'tooltip-content')]

But the above is not working when tried to get the text through .getText() call. Please help.

Upvotes: 1

Views: 167

Answers (3)

iamsankalp89
iamsankalp89

Reputation: 4739

try this it works:)

     WebElement tip = driver.findElement(By.className("tooltip-content 
               gutter-3 icon icon-small icon-error");

        String textTip = tip.getText();

       System.out.println(textTip);

Upvotes: 0

aimbire
aimbire

Reputation: 3697

This code will work as a charm, keeping your code clean, and avoiding problems if you decide to insert/change the classes inside the element:

WebElement tooltip = driver.findElement(By.id("tooltip"));
String textYouNeed = tooltip.findElement(By.className("tooltip-content")).getText();

Upvotes: 1

HemChe
HemChe

Reputation: 2337

Use the below statement to get the tooltip text.

driver.findElement(By.className("tooltip-content.gutter-3.icon.icon-small.icon-error")).getText();

Upvotes: 0

Related Questions