I am doing a exercise to use cssGetValue method to retrieve the value from a particular web element's CSS property.
I have 2 questions:
why the cssGetValue method returned value 13px, which web element does the method actually referenced.
1a. I want to get CSS property for section labeled as "By ID". how should I modify my code so I can get CSS property value for id="by-id" section?
I used driver.close() method, but it won't close the browser after the script finished. Please explain to me why driver.close() method didn't work in this case.
Here is my code fragment:
package wd_findElementBy;
import java.util.List;
import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class SearchWebElements
{
WebDriver driver = new FirefoxDriver();
private String baseUrl= "http://docs.seleniumhq.org/docs/03_webdriver.jsp#introducing-the-selenium-webdriver-api-by-example";
#Test
public void findElements(){
driver.get(baseUrl);
try{
List<WebElement> elements = driver.findElements(By.id("by-id"));
System.out.println("number of elements: " + elements.size());
for(WebElement ele : elements){
System.out.println(ele.getTagName());
System.out.println("get the text for web element with id='by-id' ");
System.out.println("------------------------------------------------------------");
System.out.println(ele.getText());
System.out.println("------------------------------------------------------------");
System.out.println(ele.getAttribute("id"));
System.out.println(ele.getCssValue("font-size"));
}
}
finally{
//driver.close();
driver.quit();
}
}
}
Yes, all correct.
Here's a screenshot of where to find font-size through Firebug.
Since the ids are supposed to be unique (at least for this page), you don't need findElements to find a list of elements with id by-id and loop through, instead, you use findElement to get the element directly.
try{
WebElement byId = driver.findElement(By.id("by-id"));
System.out.println(byId.getTagName());
System.out.println("get the text for web element with id='by-id' ");
System.out.println("------------------------------------------------------------");
System.out.println(byId.getText());
System.out.println("------------------------------------------------------------");
System.out.println(byId.getAttribute("id"));
System.out.println(byId.getCssValue("font-size"));
}
}
For getting CSS value:
driver.findElement(By.id("by-id")).getCssValue("font-size");//similarly you can use other CSS property such as background-color, font-family etc.
For quit/close the browser after finishing the execution of script:
driver.quit();
public class GetCssValues {
public WebDriver driver;
private By bySearchButton = By.name("btnK");
#BeforeClass
public void setUp() {
driver = new FirefoxDriver();
driver.get("http://www.google.com");
}
#Test(priority=1)
public void getCssValue_ButtonColor() {
WebElement googleSearchBtn = driver.findElement(bySearchButton);
System.out.println("Color of a button before mouse hover: " + googleSearchBtn.getCssValue("color"));
Actions action = new Actions(driver);
action.moveToElement(googleSearchBtn).perform();
System.out.println("Color of a button after mouse hover : " + googleSearchBtn.getCssValue("color"));
}
#Test(priority=2)
public void getCssValue_ButtonFontSize() {
WebElement googleSearchBtn = driver.findElement(bySearchButton);
System.out.println("Font Size of a button " + googleSearchBtn.getCssValue("font-size"));
}
#Test(priority=3)
public void getCssValue_ButtonFontWeight(){
WebElement googleSearchBtn = driver.findElement(bySearchButton);
System.out.println("Font Weight of a button " +getFontWeight(googleSearchBtn) );
}
public String getFontWeight(WebElement element) {
//Output will return as 400 for font-weight : normal, and 700 for font-weight : bold
return element.getCssValue("font-weight");
}
#AfterClass
public void tearDown() {
driver.quit();
}
}
output:
Color of a button before mouse hover: rgba(68, 68, 68, 1)
Color of a button after mouse hover : rgba(34, 34, 34, 1)
Font Size of a button 11px
Font Weight of a button 700
The value is correct. You need access computed section in dev-tools
Add the property name in the getCssValue to get the info regarding same
Some Examples are :-
System.out.println("font-size = "+ele.getCssValue("font-size"));
System.out.println("background = "+ele.getCssValue("background"));
System.out.println("line-height = "+ele.getCssValue("line-height"));
System.out.println("color = "+ele.getCssValue("color"));
System.out.println("font-family = "+ele.getCssValue("font-family"));
Refer:-
Related
My myntra wishlist has 41 products, of which 19 are out of stock. I tried printing the names of the 'out of stock' products.
'out of stock' elements had a common class name using which I identified the product's name using xpath by traversing through parent and child nodes.
when i validated it in console, it gave the right response. It showed 19 products and when i hovered the mouse pointer it highlighted the out of stock products as expected. Works as expected when i debugged the code too.
But when i hit run, it printed only 7 products, size of the list was 7.
The page initially displays top 20 products and later displays the remaining as we scroll down. Out of the top 20, 7 are out of stock. Could this be a reason. If that is the case, how to handle this scroll event?
Here's the code snippet:
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class stockout {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "path of chromedriver.exe");
WebDriver driver = new ChromeDriver();
WebDriverWait w =new WebDriverWait(driver,30);
driver.get(myntra login page);
//enter phone number driver.findElement(By.xpath(("//div[#class='signInContainer']/div[2]/div/input"))).sendKeys(phone number);
driver.findElement(By.cssSelector("div.submitBottomOption")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//div[#class='bottomeLink']/span")).click();
//enter password
driver.findElement(By.xpath("//input[#type='password']")).sendKeys(password);
driver.findElement(By.cssSelector("button.btn.primary.lg.block.submitButton")).click();
Thread.sleep(4000);
//open wishlist
driver.findElement(By.cssSelector("span.myntraweb-sprite.desktop-iconWishlist.sprites-headerWishlist")).click();
//add out of stock elements to a list
List<WebElement> outofstock = driver.findElements(By.xpath("//img[#class='itemcard-outOfStockItemImage itemcard-itemImage']/parent::picture/parent::a/parent::div/parent::div/div[2]/div/p[1]"));
//explicit wait
w.until(ExpectedConditions.visibilityOfAllElements(outofstock));
System.out.println(outofstock.size());
System.out.println("Items out of stock:");
for (WebElement product: outofstock)
{ System.out.println(product.getText());
}
}
}
Found the solution on the net, but wondering if there's any simpler way to do this. Suggestions are welcomed.
I added this piece of code to scroll down and it worked:
try {
Object lastHeight = ((JavascriptExecutor) driver).executeScript("return document.body.scrollHeight");
while (true) {
((JavascriptExecutor) driver).executeScript("window.scrollTo(0, document.body.scrollHeight);");
Thread.sleep(2000);
Object newHeight = ((JavascriptExecutor) driver).executeScript("return document.body.scrollHeight");
if (newHeight.equals(lastHeight)) {
break;
}
lastHeight = newHeight;
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
You can use the following code if you are expecting a specific number of elements to be present.
new WebDriverWait(driver,10).until(ExpectedConditions.numberOfElementsToBe(By by, 19));
Below is my code, which I have written while practicing Selenium webdriver. In below code linkText is not fetching required value. Done all the things given in previous answers pertaining to same issue.
package newpackage;
import org.openqa.selenium.*;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class PG9 {
public static void main(String[] args) {
System.setProperty("webdriver.ie.driver","D:\\Tools & Utilities\\IEDriverServer_x64_3.3.0\\IEDriverServer.exe");
InternetExplorerDriver driver = new InternetExplorerDriver();
String baseUrl = "http://www.monsterindia.com";
//WebDriverWait myWaitVar = new WebDriverWait(driver, 50);
driver.get(baseUrl);
//myWaitVar.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.linkText("Upload Resume")));
driver.findElement(By.linkText("Upload Resume")).click();
String expectedTitle = "Job Search | Job Vacancies | Job Opportunities in India | Monster India";
String actualTitle = "";
actualTitle = driver.getTitle();
/*
* compare the actual title of the page with the expected one and print
* the result as "Passed" or "Failed"
*/
if (actualTitle.contentEquals(expectedTitle)){
driver.findElement(By.id("name")).sendKeys("Abhay Dadhkar");
driver.findElement(By.id("mob_no")).sendKeys("9011134418");
driver.findElement(By.id("wordresume")).sendKeys("D:\\Abhay\\Abhay_Training_Profile\\Training_Profile\\AbhayDadhkar_Detail_Profile_Jan2017.docx");
} else
{
System.out.println("Test Failed");
}
driver.close();
// enter the file path onto the file-selection input field
WebElement uploadElement = driver.findElement(By.name("File name"));
uploadElement.sendKeys("D:\\Automation tools\\Selenium\\Selenium_Practice\\newhtml.html");
// check the "I accept the terms of service" check box
//driver.findElement(By.name("Open")).click();
// click the "UploadFile" button
driver.findElement(By.name("Open")).click();
}
}
By.linkText works only on <a> tags. If you want to locate by text use xpath instead
driver.findElement(By.xpath("//span[contains(., 'Upload Resume')]")).click();
You can also click the parent <div>
driver.findElement(By.className("fileUpload")).click();
I have created two sets of code contained in two seperate classes
Task Required: need to click on the 'Cash' button on the PH payment page.
Class one = simple class, simple code = code works and can click on the cash option.
Class two = setup contains page objects, framework uses different structure = code is unable to click on the cash option when reaching the payment page = 'org.openqa.selenium.StaleElementReferenceException: Element not found in the cache'
I have used the same locators within both classes but when uses the correct locator in '2' its unable to click on the 'radio' button; as listed above i get the listed error; i have tried to create bespoke methods; using loops etc and different locators but nothing works.
Working code and class:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
public class TestClass {
#Test
public void test() throws InterruptedException {
//System.setProperty("webdriver.chrome.driver", "C:\\Users\\GBruno\\Desktop\\masteringSelenium\\Framework\\src\\test\\resources\\chromedriver.exe");
// WebDriver driver = new ChromeDriver();
WebDriver driver = new FirefoxDriver();
driver.get("http://www.pizzahut.co.uk");
driver.manage().window().maximize();
//click pizza button
driver.findElement(By.cssSelector("div[id='page'] [href='/menu/pizza']")).click();
//select any pizza to start order
driver.findElement(By.cssSelector("div[class='col-xxs-8 col-xs-6 col-sm-8 col-md-7 col-lg-6'] *> button")).click();
//enter postcode and find hut
Thread.sleep(2000);
driver.findElement(By.cssSelector("#ajax-postcode-txt")).sendKeys("TS1 4AG");
driver.findElement(By.cssSelector(" #get-store-btn")).click();
//click start order button
Thread.sleep(3000);
driver.findElement(By.xpath(".//*[#id='store-collection-section']/div[2]/div[4]/div[4]/div/a")).click();
//add pizza
Thread.sleep(5000);
driver.findElement(By.xpath(".//*[#id='pizza-product-list']/div/div[1]/div/div[2]/div[2]/div[3]/div/form/button")).click();
//click mini basket
driver.findElement(By.xpath("html/body/nav/div/div/div[3]/div/div[1]/div[2]/span[3]")).click();
Thread.sleep(2000);
//click checkout
driver.findElement(By.xpath(".//*[#id='divBasket']/div[1]/div/div[2]/div[2]/a")).click();
Thread.sleep(2000);
//checkout guest & enter details
driver.findElement(By.xpath(".//*[#id='frmCheckout']/div[2]/div/div[1]/a")).click();
driver.findElement(By.xpath(".//*[#id='ddlTitleSelectBoxIt']")).click();
driver.findElement(By.linkText("Mr")).click();
driver.findElement(By.xpath(".//*[#id='FirstName']")).sendKeys("Tom");
driver.findElement(By.xpath(".//*[#id='LastName']")).sendKeys("Hanks");
driver.findElement(By.xpath(".//*[#id='EmailAddress']")).sendKeys("tom_hanks12344566#mail.com");
driver.findElement(By.xpath(".//*[#id='ConfirmEmailAddress']")).sendKeys("tom_hanks12344566#mail.com");
driver.findElement(By.xpath(".//*[#id='PhoneNumber']")).sendKeys("01234 5647890");
driver.findElement(By.xpath(".//*[#id='btnFindAddress']")).click();
Thread.sleep(3000);
driver.findElement(By.xpath(".//*[#id='ddlAddressesToChooseSelectBoxItArrowContainer']")).click();
driver.findElement(By.linkText("K F C 189-191 Linthorpe Road Middlesbrough TS14AG")).click();
driver.findElement(By.xpath(".//*[#id='btnContinue']")).click();
driver.findElement(By.xpath(".//*[#id='payment-methods']/div[1]/div/label/input")).click();
}
}
Code dosnt work:
public void selectPaymentTypeAndPayForOrder() throws Exception {
Thread.sleep(3000);
driver.findElement(By.xpath(".//*[#id='payment-methods']/div[1]/div/label/input")).click();
driver.findElement(By.cssSelector(" form[id='CheckoutForm'] input[data-paymentname='Cash']")).click();
The following code resolved the issue:
List<WebElement> iframes = driver.findElements(By.tagName("iframe"));
if(iframes.size() == 0) {
Assert.fail();
} else {
// Frames present
Assert.assertTrue(true);
}
Problem: Automation with iOS Actual device using Appium, all i am trying is to scroll down to a particular element which is not in the current page and select that element./click on that element.
Used so far:
used scrollTo("text") and scrollToexact("text") - came to know that this is depricated now in java-client . Just want to double confirm is it true?
did try to use the below,but still no luck
MobileElement slider = driver
.findElement(MobileBy
.IosUIAutomation(".tableViews()[0]"
+ ".scrollToElementWithPredicate(\"name CONTAINS 'Slider'\")"));
assertEquals(slider.getAttribute("name"), "Sliders");
It would be helpful if some one could help me resolve this, also would like to do the scroll for android later as well, have not tried it yet.
Below is the code where i have used various techniques but still no success,the code runs launches the app,but does not scroll and select any element:
import java.io.File;
import java.net.URL;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileElement;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.ios.IOSElement;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class testfour {
public static IOSDriver driver;
#BeforeClass
public static void setUpBeforeClass() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
//capabilities.setCapability("noReset", true);
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("deviceName","iPhone_6");
capabilities.setCapability("udid", "840384833537f40d011032eaaf20a53705a451ce");
capabilities.setCapability("BROWSER_NAME", "iOS");
capabilities.setCapability(CapabilityType.VERSION, "9.2.1");
capabilities.setCapability(CapabilityType.PLATFORM, "MAC");
capabilities.setCapability("autoAcceptAlerts", true);
capabilities.setCapability("autoAcceptAlerts", true);
driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void test() throws InterruptedException {
System.out.println("TEST STARTED");
//Make
driver.findElementByXPath("//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIATableView[1]/UIATableCell[6]/UIAStaticText[1]").click();
System.out.println("TEST STARTED6 MAKE");
//Select Audi and model a8
driver.findElementByXPath("//UIAApplication[1]/UIAWindow[1]/UIATableView[2]/UIATableCell[8]/UIAStaticText[1]").click();
System.out.println("TEST STARTED5 AUDI");
driver.findElementByXPath("//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIATableView[1]/UIATableCell[8]/UIAStaticText[2]").click();
System.out.println("TEST STARTED4 MODEL");
//driver.findElementByXPath("//UIAApplication[1]/UIAWindow[1]/UIATableView[2]/UIATableCell[17]/UIAStaticText[1]").click();
System.out.println("TEST STARTED3");
//String Str = "A8";
System.out.println("TEST STARTED2");
//MobileElement slider = (MobileElement) driver.findElement(MobileBy.IosUIAutomation(".tableViews()[2]"+ ".scrollToElementWithPredicate(\"name CONTAINS 'Slider'\")"));
MobileElement slider = (MobileElement) driver.findElement(MobileBy.IosUIAutomation("//UIAApplication[1]/UIAWindow[1]/UIATableView[2]/UIATableCell[17]"+ ".scrollToElementWithPredicate(\"name CONTAINS 'A8'\")"));
System.out.println("TEST STARTED1");
assertEquals(slider.getAttribute("A8"), "Sliders");
System.out.println("TEST STARTED0");
// MobileElement table = (MobileElement) driver.findElement(MobileBy.IosUIAutomation(".tableViews()[0]"));
// MobileElement slider = (MobileElement) table.findElement(MobileBy.IosUIAutomation(".scrollToElementWithPredicate(\"name CONTAINS 'Slider'\")"));
// assertEquals(slider.getAttribute("name"), "Sliders");
//driver.findElementByIosUIAutomation(".scrollToElementWithName(\""+ Str + "\")").click();
//WebElement tableView = driver.findElementByIosUIAutomation(".tableViews() [2]");
//((IOSElement) tableView).scrollTo("A8");
//((IOSElement) tableView).scrollTo("A8").click();
System.out.println("TEST STARTED1");
//driver.execute("mobile: scroll", [{direction: 'down', driver.findElementByXPath: ("//UIAApplication[1]/UIAWindow[1]/UIATableView[2]/UIATableCell[17]/UIAStaticText[1]"}]);
//driver.scrollTo("A8").click();
//JavascriptExecutor jes = (JavascriptExecutor) driver;
//HashMap<String, String> scrollObject = new HashMap<String, String> ();
//scrollObject.put("direction", "down");
//scrollObject.put("element", (driver.findElementByXPath("//UIAApplication[1]/UIAWindow[1]/UIATableView[2]/UIATableCell[17]/UIAStaticText[1]")));
//jes.executeScript("mobile: scroll", scrollObject);
//jes.executeScript(arg0, arg1)
//driver.swipe(startx, starty, endx, endy, duration);
//driver.switchTo()
//jes.executeScript("arguments[0].scrollIntoView(true);", driver.findElementByXPath("//UIAApplication[1]/UIAWindow[1]/UIATableView[2]/UIATableCell[17]/UIAStaticText[1]"));
//driver.findElementByXPath("//UIAApplication[1]/UIAWindow[1]/UIAButton[7]").click();
// driver.scrollToExact(text)
// driver.scrollTo("//UIAApplication[1]/UIAWindow[1]/UIAButton[7]").click();
//Select Model000
driver.findElement(By.linkText("All Models")).click();
driver.findElement(By.linkText("AVALON")).click();
//Click on Search button
driver.findElement(By.id("search_btn")).click();
// Click on the Search Alert Bar
driver.findElement(By.id("switchButton")).click();
//ex: for content-desc //Click on the Back button and navigate to home page
driver.findElement(By.name("Navigate up")).click();
//Now click on the Menu in the home page
driver.findElement(By.name("Navigate up")).click();
//Click on the Search Search under the menu item
driver.findElementByLinkText("Saved Searches").click();
//get the text
String text = driver.findElement(By.id("name_tv")).getText();
System.out.println("Actual Text:"+text);
System.out.println("Test has been completed");
}
private void assertEquals(String attribute, String string) {
// TODO Auto-generated method stub
}
#AfterClass
public void tearDown()
{
driver.quit();
}
}
Realize this is old, but came across it searching for a different problem and thought I could help.
What I do here is use Appium "swipe".
First, I get the size of my screen:
Dimension size = driver.manage().window().getSize();
Then, I swipe the screen down:
driver.swipe(size.width / 3, (int) (size.height * 0.8), size.width / 3, (int) (size.height * 0.8) - 200, 300);
After swiping, I call a boolean method to look for the element which returns:
return driver.findElement(Bylocator).isDisplayed();
I have this swipe action/isDisplayed check wrapped in a FluentWait, but a simple while loop with some sort of timeout condition and the isDisplayed check would work too.
After the element has been swiped to and found, a simple click call will complete your request.
(Note: I use this process for iOS and Android, so it should work on both platforms for you, too.)
TL;DR - use driver.swipe, check if element is displayed. If not, swipe and check again. wrap in loop of your choice until element is found or loop timeout hits.
Below is the HTML Query.
<div id="dvCount" style="">
<span>Total Log Count : </span>
<span id="spnLogCount">46</span>
</div>
I want to print the value 46 in Selenium WebDriver. Please let me know the code.
I am using the following code but I am unable to get the value:
WebElement Text= driver.Findelement(By.cssselector(xpath).gettext();
system.out.println("total" + Text);
But this code is not working. How do I properly get to the value in the "spnLogCount" tag?
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.get("file:///C:/Users/rajnish/Desktop/my.html");
// way one
// you can create your custom x path
// one x path can be made directly using id of the span like
// xpath = //span[#id='spnLogCount']
// also not if you are not sure of the tag name then you can also use * in xpath like below
String myText = driver.findElement(By.xpath("//*[#id='dvCount']/span[2]")).getText();
System.out.println("Total Log Count : " + myText);
// way two
// you can directly use id
myText = driver.findElement(By.id("spnLogCount")).getText();
System.out.println("Total Log Count : " + myText);
// way three
// if you are using css selector then for id you can use #
myText = driver.findElement(By.cssSelector("#spnLogCount")).getText();
System.out.println("Total Log Count : " + myText);
}
UPDATE
driver.findElement(By.id("ui-id-3")).click();
driver.findElement(By.linkText("Info Log")).click();
driver.findElement(By.id("txtMessage")).sendKeys("Push Success");
driver.findElement(By.id("txtMachineName")).sendKeys("AC204");
driver.findElement(By.id("txtPortal")).sendKeys("91");
driver.findElement(By.id("btnSearch")).click();
// use it just before the sendkeys code like this
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#id='dvCount']/span[2]")));
String text = driver.findElement(By.xpath("//*[#id='dvCount']/span[2]")).getText();
System.out.println(text);
Hope this helps
I think you want something like this:
WebElement textElement = driver.findElement(By.xpath(".//div/span"));
String text = textElement.getText();
System.out.println("Value: " + text);
String text=driver.findElement(By.xpath("//span[#id='spnLogCount']")).getText();
System.out.println(text);
I updated you code, please use below it will work.
String Text= driver.findElement(By.cssselector("#spnLogCount")).gettext();
System.out.println("total" + Text);
As a JUnit test (and using WebDriverManager to handle the gecko driver):
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import io.github.bonigarcia.wdm.FirefoxDriverManager;
public class FirefoxTest {
private WebDriver driver;
#BeforeClass
public static void setupClass() {
FirefoxDriverManager.getInstance().setup();
}
#Before
public void setup() {
driver = new FirefoxDriver();
}
#After
public void teardown() {
if (driver != null) {
driver.quit();
}
}
#Test
public void test() {
driver.get("http://localhost:8080"); // Here your URL
WebElement webElement = driver.findElement(By.id("spnLogCount"));
System.out.println(webElement.getText());
}
}