Filter by tags:
May 18, 2020
Locators for selenium | linkText locator example | anchor tag link text click example in selenium
( JasperSoft BI Suite Tutorials - Sadakar Pochampalli )
Hi,
In this post, you will see the demonstration of "linkText" locator usage. For the purposes, I took my blog-site https://jasper-bi-suite.blogspot.com/.
linkText is one of the 8 locators supported by selenium, using it one can navigate to target page by performing click action.
For instance, navigate to "Services" page from the site.
Let's see how to perform/navigate to Services page using "Services" text from the following HTML script.
The following statement identifies "Services" link on the page and does the click action.
Take a look at the complete java code at the bottom or watch below 1 min video tutorial for end-to-end execution.
Screenshot:
Watch this 1 min video tutorial ( change quality to 720p)
linkTextDemo.java
In this post, you will see the demonstration of "linkText" locator usage. For the purposes, I took my blog-site https://jasper-bi-suite.blogspot.com/.
linkText is one of the 8 locators supported by selenium, using it one can navigate to target page by performing click action.
For instance, navigate to "Services" page from the site.
Let's see how to perform/navigate to Services page using "Services" text from the following HTML script.
<a href="https://jasper-bi-suite.blogspot.com/p/contact-information.html">Services </a>
The following statement identifies "Services" link on the page and does the click action.
driver.findElement(By.linkText("Services")).click();
Take a look at the complete java code at the bottom or watch below 1 min video tutorial for end-to-end execution.
Screenshot:
Watch this 1 min video tutorial ( change quality to 720p)
linkTextDemo.java
package selenium.locators.examples;
//linkText example
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class linkTextDemo {
public static void main(String[] args) {
WebDriver driver ;
System.setProperty("webdriver.chrome.driver", "D:\\006_trainings\\chromedriver.exe");
System.setProperty("webdriver.chrome.silentOutput", "true");
driver = new ChromeDriver();
driver.navigate().to("https://jasper-bi-suite.blogspot.com/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//linkText
driver.findElement(By.linkText("Services")).click();
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0,550)");
//driver.close();
}
}
- Sadakar Pochampalli
May 18, 2020
Selenium installation in Eclipse and launch a website using navigate().to() method
( JasperSoft BI Suite Tutorials - Sadakar Pochampalli )
Hi ,
This tutorial is intended to written for beginners and in this example, we would see how to set-up and launch a website in chrome browser (for example: https://jasper-bi-suite.blogspot.com/) using java selenium.
1. Download Eclipse zip from https://www.eclipse.org/downloads/
2. Install java 1.8 or later and set path & class path in windows os.
3. Download suitable chromedriver.exe from https://chromedriver.chromium.org/downloads
NOTE : This example is tested on : Version 81.0.4044.138 (Official Build) (64-bit)
4. Download selenium jar files and configure in Eclipse Build Path as (Referenced Libraries)
https://www.selenium.dev/downloads/
5. Write FirstTestCase.java class with the code shown in below.
6. Run as "Java Applicaiton".
In the java class, ensure to have the following :
1) System set property - using this call the chromedriver.exe
2) Declaring driver - driver declaration
3) navigate().to - method to navigate to a given site.
4) ChromeOptions options = new ChromeOptions();
.......... Google Chrome Browser Options.............
driver = new ChromeDriver(options);
Watch this ~15 sec video for execution of this case.
This tutorial is intended to written for beginners and in this example, we would see how to set-up and launch a website in chrome browser (for example: https://jasper-bi-suite.blogspot.com/) using java selenium.
1. Download Eclipse zip from https://www.eclipse.org/downloads/
2. Install java 1.8 or later and set path & class path in windows os.
3. Download suitable chromedriver.exe from https://chromedriver.chromium.org/downloads
NOTE : This example is tested on : Version 81.0.4044.138 (Official Build) (64-bit)
4. Download selenium jar files and configure in Eclipse Build Path as (Referenced Libraries)
https://www.selenium.dev/downloads/
5. Write FirstTestCase.java class with the code shown in below.
6. Run as "Java Applicaiton".
In the java class, ensure to have the following :
1) System set property - using this call the chromedriver.exe
2) Declaring driver - driver declaration
3) navigate().to - method to navigate to a given site.
4) ChromeOptions options = new ChromeOptions();
.......... Google Chrome Browser Options.............
driver = new ChromeDriver(options);
Watch this ~15 sec video for execution of this case.
import java.util.concurrent.TimeUnit;
/**
* @author Sadakar Pochampalli
*/
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class FirstTestCase {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "D:\\006_trainings\\chromedriver_win32\\chromedriver.exe");
WebDriver driver ;
ChromeOptions options = new ChromeOptions();
//options.addArguments("--headless");
options.addArguments("--disable-gpu");
options.addArguments("start-maximized");
options.setPageLoadStrategy(PageLoadStrategy.NONE);
options.addArguments("--allow-insecure-localhost");
options.addArguments("--allow-running-insecure-content");
options.addArguments("--ignore-certificate-errors");
options.addArguments("--no-sandbox");
options.addArguments("--window-size=1280,1000");
options.setCapability("acceptSslCerts", true);
options.setCapability("acceptInsecureCerts", true);
driver = new ChromeDriver(options);
driver.navigate().to("https://jasper-bi-suite.blogspot.com/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//driver.close();
}
}
May 18, 2020
May 11, 2020
C# : Error CS0120 An object reference is required for the non-static field, method, or property
( JasperSoft BI Suite Tutorials - Sadakar Pochampalli )
In C#, if you try to print a non-static variable from static method, you will see the reference error message.
I wanted to check this example both in C# and Core Java and so if you are wondering how the similar behavior appears in core java , take a look at this example@
Severity Code Description Project File Line Suppression State
Error CS0120 An object reference is required for the non-static field, method, or property 'Car.color' ConsoleApp3 C:\Users\sadakar\source\repos\ConsoleApp3\ConsoleApp3\Oops\ClassesAnbObjects\Car.cs 15 N/A
I wanted to check this example both in C# and Core Java and so if you are wondering how the similar behavior appears in core java , take a look at this example@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp3.Oops.ClassesAnbObjects
{
class Car
{
string color = "red";
static void Main(string[] args)
{
Car myObj = new Car();
Console.WriteLine(color);
Console.ReadLine();
}
}
}
Solution:
1) Create an Object
2) Call/print the non static variable using object.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp3.Oops.ClassesAnbObjects
{
class Car
{
string color = "red";
static void Main(string[] args)
{
Car myObj = new Car();
Console.WriteLine(myObj.color);
Console.ReadLine();
}
}
}
References:
https://stackoverflow.com/questions/498400/cs0120-an-object-reference-is-required-for-the-nonstatic-field-method-or-prop
May 11, 2020
Core Java : Cannot make a static reference to the non-static field
( JasperSoft BI Suite Tutorials - Sadakar Pochampalli )
If you try to access an instance variable or say non-static variable in a static method, you would end up with static reference error message.
For instance, in the following example, variable "a" is class variable/non-static instance variable and if accessed directly in the static method, say in this case it is main method, it would throw the reference exception.
For instance, in the following example, variable "a" is class variable/non-static instance variable and if accessed directly in the static method, say in this case it is main method, it would throw the reference exception.
NonStaticDataMemberInStaticMethod.java
package static1.method;
public class NonStaticDataMemberInStaticMethod {
int a=10 ;// non static variable
public static void main(String args[]) {
System.out.println(a);
}
}
Error Message:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Cannot make a static reference to the non-static field a
at static1.method.NonStaticDataMemberInStaticMethod.main(NonStaticDataMemberInStaticMethod.java:7)
Solution:
1) Create an Object
2) Call/print the non static variable using object.
package static1.Variable;
public class NonStaticDataMemberInStaticMethod {
int a =10;//non static variable
public static void main(String args[]) {
NonStaticDataMemberInStaticMethod myObj=new NonStaticDataMemberInStaticMethod();
System.out.println(myObj.a);
}
}

- Sadakar Pochampalli
May 11, 2020
April 30, 2020
Tip : None of the features at [classpath:features] matched the filters: [@scenario_AddMarketingAcco…
( JasperSoft BI Suite Tutorials - Sadakar Pochampalli )
Hi,
If we try to provide tags individually as below in main method for command line usage, we may end-up getting the error message saying .. None of the features at classpath matched the filters."-t","@scenario_AddMarketingAccount,
"-t","@scenario_AddMarketingUser",
None of the features at [classpath:features] matched the filters: [@scenario_AddMarketingAccount, @scenario_AddMarketingUser]
0 Scenarios
0 Steps
0m0.000s
Provide a single tag with comma separated literals/scenario tags.
i.e.,
"-t","@scenario_AddMarketingAccount,@scenario_AddMarketingUser"
Below is how the tags should be written for CLI (command line interface)
package com.sadakar.selenium.common;
import org.openqa.selenium.WebDriver;
public class BasePage {
public static WebDriver driver;
public static void main(String args[]) throws Throwable{
try {
cucumber.api.cli.Main.main(
new String[]{
"classpath:features",
"-g", "com.sadakar.cucumber.stepdefinitions/",
"-g","com.sadakar.cucumber.common",
"-t","@scenario_AddMarketingAccount,@scenario_AddMarketingUser",
"-p","pretty",
"-p","json:target/cucumber-reports/Cucumber.json",
"-p", "html:target/cucumber-reports",
"-m"
}
);
}
catch(Throwable e) {
e.printStackTrace();
System.out.println("Main method exception");
}
}
}
NOTE :
When you run executable jar file, it executes ALL the scenarios given with "-t" tag.
1) Build the jar file
clean compile assembly:single install
2) Run the jar file
java -DtestEnv=local -jar SADAKAR_POC-0.0.1-SNAPSHOT-jar-with-dependencies.jar
April 30, 2020
Tip : Run specific cucumber scenario from command line for an executable jar file
( JasperSoft BI Suite Tutorials - Sadakar Pochampalli )
Hi,
Syntax:
java -Dcucumber.options="-tags @<ScenarioName>" - jar <executable-jar-file>
java -Dcucumber.options="--tags @scenario_AddUser" -jar SADAKAR_CUCUMBER_POC-0.0.1-SNAPSHOT-jar-with-dependencies.jar
Snapshot:
References:
https://stackoverflow.com/questions/37559861/run-a-single-cucumber-scenario-from-an-executable-jar
Syntax:
java -Dcucumber.options="-tags @<ScenarioName>" - jar <executable-jar-file>
java -Dcucumber.options="--tags @scenario_AddUser" -jar SADAKAR_CUCUMBER_POC-0.0.1-SNAPSHOT-jar-with-dependencies.jar
Snapshot:
References:
https://stackoverflow.com/questions/37559861/run-a-single-cucumber-scenario-from-an-executable-jar
April 30, 2020
April 30, 2020
April 22, 2020
Tip : Code snippet of isSelected() and getAttribute("value") to validate checkbox in a St…
( JasperSoft BI Suite Tutorials - Sadakar Pochampalli )
Hi,
Use case : In a Store page form,
PASS the test : if the store belongs to an internal office
FAIL the test : if the store belongs to external office for sales
NOTE : While creating the Store in the form selected the checkbox so it is an internal store.
label and input type : Is Internal Store ( it is a check box )
- Sadakar Pochampalli
Use case : In a Store page form,
PASS the test : if the store belongs to an internal office
FAIL the test : if the store belongs to external office for sales
NOTE : While creating the Store in the form selected the checkbox so it is an internal store.
label and input type : Is Internal Store ( it is a check box )
@Then("^I verify all the Store details with the values given while creating a new Store$")
public void i_verify_all_the_Store_details_with_the_values_given_while_creating_a_new_Store() throws Throwable {
try {
Log.debug("Comparing Internal Store with the selection while a new Store is created");
Log.debug("Internal Store value while the Store is created is=true");
Log.debug("Get Value of internal Store from UI: "+driver.findElement(By.xpath("//*[@id='isInternalStore']")).getAttribute("value"));
if(
(driver.findElement(By.xpath("//*[@id='isInternalStore']")).isSelected()) &&
(driver.findElement(By.xpath("//*[@id='isInternalStore']")).getAttribute("value").toString().equals("true"))
) {
Log.debug("Store is equals with the selection while account is created");
}else
{
Assert.fail("else block.......... Store is NOT internal one");
System.out.println("Store is NOT internal one");
}
}catch(Exception e) {
Assert.fail("catch block.........Store is NOT internal one"+e);
System.out.println("Store is NOT internal one"+e);
}
}
- Sadakar Pochampalli
April 22, 2020
April 14, 2020
AutoIT script for windows based chrome authentication in Selenium or Cucumber
( JasperSoft BI Suite Tutorials - Sadakar Pochampalli )
Hi,
The following AutoIt script can be used for windows based chrome authentication.
1. Open the website in chrome with windows based pop-up.
2. Open the AutoIT tool and move the "Finder Tool" on to the window.
3. Make a note of "Title" and "Class" of the window.
4. Use the following script with values updated with the "Title" and "Class".
5. Save the file, for example : atuoit_chrome_credentials.au3 (extension should be .au3)
6. Compile the script (right click from the location where the file is saved and compile).
7. Compile generates .exe file , in this case it is : atuoit_chrome_credentials.exe
Call the .exe file before the website get loaded in java file
AutoIT code snippet
How to find Title and Class from AutoIt tool ?
Auto reads the credentials while the program runs for chrome based windows authentication pop-up.
- Sadakar Pochampalli
The following AutoIt script can be used for windows based chrome authentication.
1. Open the website in chrome with windows based pop-up.
2. Open the AutoIT tool and move the "Finder Tool" on to the window.
3. Make a note of "Title" and "Class" of the window.
4. Use the following script with values updated with the "Title" and "Class".
5. Save the file, for example : atuoit_chrome_credentials.au3 (extension should be .au3)
6. Compile the script (right click from the location where the file is saved and compile).
7. Compile generates .exe file , in this case it is : atuoit_chrome_credentials.exe
Call the .exe file before the website get loaded in java file
Runtime.getRuntime().exec("\path to the .exe file\"+"autoit_chorme_credentials.exe");
AutoIT code snippet
;RequireAdmin ; unsure if it's needed
;$iSleep = 2000
Opt("WinSearchChildren", 1)
$sUsername = "admin"
$sPassword = "PaSSWorD2%"
Sleep(1000)
For $i = 1 To 20 Step 1
Sleep(3000)
$sTitle = WinGetTitle("Sign in")
If $sTitle = "sadakar.network.com - Google Chrome" or WinWaitActive("[CLASS:Chrome_WidgetWin_1]") or WinWaitActive("Sign in") Then
Send($sUsername)
Send("{TAB}")
Send($sPassword,1);$SEND_RAW (1)
Send("{TAB}")
Send("{ENTER}")
Exit 0
Else
ContinueLoop
EndIf
Next
Exit 1
How to find Title and Class from AutoIt tool ?
Auto reads the credentials while the program runs for chrome based windows authentication pop-up.
- Sadakar Pochampalli
April 14, 2020
April 13, 2020
Tip : Multiple markers at this line - Step definitions detection works only when the project is con…
( JasperSoft BI Suite Tutorials - Sadakar Pochampalli )
This is usually seen in the feature file as a warning message.
If you install feature file plugin from eclipse market place and if you restart the tool, the existing feature files gets this warning.
I've observed it in the following eclipse installation:
Version: 2020-03 (4.15.0)
Build id: 20200313-1211
Right click on the eclipse project -> Configure --> Convert to Cucumber Project...
References:
https://stackoverflow.com/questions/58327032/step-definition-detection-only-works-when-project-is-configured-as-cucumber-proj
April 13, 2020
Pages
About
Planet Jaspersoft aggregates blog posts from our community. If you would like your blog to be included in the Planet, please follow this help guide. Or just click this link to go straight to your Planet Feeds.
Feed Sources
- JasperSoft BI Suite Tutorials - Sadakar Pochampalli (217) Apply JasperSoft BI Suite Tutorials - Sadakar Pochampalli filter
- Jaspersoft Tutorials (50) Apply Jaspersoft Tutorials filter
- Technology Blog (50) Apply Technology Blog filter
- Jaspersoft Tech Talks (47) Apply Jaspersoft Tech Talks filter
- The Open Book on BI (26) Apply The Open Book on BI filter
- Rajesh Sirsikar (22) Apply Rajesh Sirsikar filter
- Bekwam Data as a Service (21) Apply Bekwam Data as a Service filter
- AgileTech - Ankur Gupta (19) Apply AgileTech - Ankur Gupta filter
- Ankur Gupta - Youtube (17) Apply Ankur Gupta - Youtube filter
- Digital Gene (15) Apply Digital Gene filter
- Tech Poet (13) Apply Tech Poet filter
- iTransparent - Jaspersoft Blog (9) Apply iTransparent - Jaspersoft Blog filter
- Paco Saucedo's blog » JasperReports (6) Apply Paco Saucedo's blog » JasperReports filter
- David Hoppmann's JasperServer Posts (2) Apply David Hoppmann's JasperServer Posts filter
- Jasper Related Posts from Wedjaa (1) Apply Jasper Related Posts from Wedjaa filter
- Kamal's YouTube videos (1) Apply Kamal's YouTube videos filter