Page is not being driven - java

Can someone tell me why my page is not being driven using the code below? The page loads but the driver does not drive to click the ticketButton link. I am lost and could use some help. Thanks in advance.
package domainEntities;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class ConstantsTest {
WebDriver driver;
public ConstantsTest(WebDriver driver){
this.driver = driver;
}
public WebElement ticketButton() {
WebElement ticketButton = driver.findElement(By.cssSelector("a.ticketButton"));
return ticketButton();
}
}
package test;
import domainEntities.ConstantsTest;
import org.junit.After;
import org.junit.Test;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import static org.junit.Assert.fail;
public class TenaciousD{
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
WebDriver driver = new FirefoxDriver();
#Test
public void TenaciousD() throws InterruptedException {
driver.get("http://tenaciousd.com");
ConstantsTest c = new ConstantsTest(driver);
c.ticketButton().click();
Thread.sleep(100000);
}
This is the error its returning:
java.lang.StackOverflowError
at java.io.FileInputStream.<init>(FileInputStream.java:56)
at java.net.SocketInputStream.<init>(SocketInputStream.java:61)
at java.net.AbstractPlainSocketImpl.getInputStream(AbstractPlainSocketImpl.java:415)
at java.net.Socket$2.run(Socket.java:875)
at java.net.Socket$2.run(Socket.java:873)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.Socket.getInputStream(Socket.java:872)
at org.apache.http.impl.io.SocketInputBuffer.<init>(SocketInputBuffer.java:85)
at org.apache.http.impl.SocketHttpClientConnection.createSessionInputBuffer(SocketHttpClientConnection.java:107)
at org.apache.http.impl.conn.DefaultClientConnection.createSessionInputBuffer(DefaultClientConnection.java:184)
at org.apache.http.impl.SocketHttpClientConnection.bind(SocketHttpClientConnection.java:163)
at org.apache.http.impl.conn.DefaultClientConnection.openCompleted(DefaultClientConnection.java:132)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:186)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:151)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:125)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:640)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:479)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:316)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:295)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:133)
at org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:355)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:307)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByCssSelector(RemoteWebDriver.java:396)
at org.openqa.selenium.By$ByCssSelector.findElement(By.java:406)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299)
at domainEntities.ConstantsTest.ticketButton(ConstantsTest.java:23)

Your StackOverflow issue is coming from your ticketButton() method.
public WebElement ticketButton() {
WebElement ticketButton = driver.findElement(By.cssSelector("a.ticketButton"));
return ticketButton();
}
You are returning the method instead of the element.
public WebElement ticketButton() {
WebElement ticketButton = driver.findElement(By.cssSelector("a.ticketButton"));
return ticketButton;
}

Related

TestNG Null Pointer Exception error when working on a page opened by a previous test case

I am using TestNG and Page Object Model.
I have created some test cases. I see that the first two test cases are working. But, the third test case starts on a new page which is opened by the second test case. I am unable to interact with the new page, and getting a Null Pointer Exception error. Not sure what went wrong.
I have three Java classes Here.
This is my base class:
package MYQC_Reusable_Classes;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
public class MYQC_Base_Class {
public static WebDriver driver = null;
// public static ExtentTest Logger = null;
// public static ExtentReports report = null;
#BeforeSuite
public void initialize() throws IOException {
// report = new ExtentReports("C:\\Users\\fhasan\\Desktop\\ExtentReport"+".html");
System.setProperty("webdriver.chrome.driver", "C:\\Users\\fhasan\\Desktop\\driver\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();`enter code here`
// add the precondition arguments
options.addArguments("start-maximized", "incognito");
driver = new ChromeDriver(options);
// To maximize browser
driver.manage().window().maximize();
// Implicit wait
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
#BeforeMethod
public void timer(){
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
#AfterSuite
// Test cleanup
public void TeardownTest() throws InterruptedException {
Thread.sleep(4000);
MYQC_Base_Class.driver.quit();
}
}
This is my page class:
package MYQC_Browser_Pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
public class MYQC_Login_Page {
WebDriver driver;
// constructor that will be automatically called as soon as the object of the
// class is created
public MYQC_Login_Page(WebDriver driver) {
this.driver = driver;
}
#FindBy(how = How.ID, using = "loginName")
public static WebElement userNameField;
#FindBy(how = How.ID, using = "loginPassword")
public static WebElement passwordField;
#FindBy(how = How.ID, using = "loginButton")
public static WebElement clickLogin;
//Method to enter username
public void clickUserName() {
userNameField.click();
}
public void enterUserName(String user) {
userNameField.sendKeys(user);
}
public void clickPass() {
passwordField.click();
}
public void enterPassword(String pass) {
passwordField.sendKeys(pass);
}
//Method to click on Login button
public void clickLoginButton() {
clickLogin.click();
}
}
This is my first test case which works fine:
package MYQC_TestCase_Classes;
import MYQC_Browser_Pages.CUST4_MYQC_Login_Selection_Page;
import MYQC_Reusable_Classes.MYQC_Base_Class;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.support.PageFactory;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.io.File;
import java.io.IOException;
import java.util.PriorityQueue;
public class TC001_MYQC_Login_Selection_Button_Text extends MYQC_Base_Class {
#Test()
public void MYQC_Login_Button_Text() throws InterruptedException, IOException {
//creating anb object of the CUST4_MYQC_Login_Selection_Page
CUST4_MYQC_Login_Selection_Page go_To_MYQC_Page = PageFactory.initElements(driver, CUST4_MYQC_Login_Selection_Page.class);
// going to the cust4 myqc link
driver.get("https://mmhcustfour.com");
Thread.sleep(3000);
Assert.assertEquals(go_To_MYQC_Page.buttonText(), "Login with Quickcharge Authentication");
//System.out.print( go_To_MYQC_Page.buttonText());
}
}
This is my second test case (on the same page) which also works fine:
package MYQC_TestCase_Classes;
import MYQC_Browser_Pages.CUST4_MYQC_Login_Selection_Page;
import MYQC_Browser_Pages.MYQC_Login_Page;
import MYQC_Reusable_Classes.MYQC_Base_Class;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.io.File;
import java.io.IOException;
public class TC002_MYQC_Login_Selection_Test extends MYQC_Base_Class {
#Test
public void Go_To_MYQC_Login_Page_Test() throws InterruptedException, IOException {
//creating anb object of the CUST4_MYQC_Login_Selection_Page
CUST4_MYQC_Login_Selection_Page go_To_MYQC_Page = PageFactory.initElements(driver, CUST4_MYQC_Login_Selection_Page.class);
//Clicking on the button to go to the MYQC login page
go_To_MYQC_Page.preClickLogin();
// waiting few seconds to get a screenshot of the page
Thread.sleep(2000);
File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(src, new File("C:\\Users\\fhasan\\Desktop\\Selenium Screenshots\\MYQCLogin_Page.png"));
Thread.sleep(2000);
}
}
This is my third test case class: (which creates the error)
package MYQC_TestCase_Classes;
import MYQC_Browser_Pages.MYQC_Login_Page;
import MYQC_Reusable_Classes.MYQC_Base_Class;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class TC003_MYQC_Prepaid_Login_Test extends MYQC_Base_Class {
//creating an object of the page
MYQC_Login_Page login_page = PageFactory.initElements(driver,MYQC_Login_Page.class);
#Test
public void MYQC_Login() throws InterruptedException {
Thread.sleep(2000);
login_page.clickUserName();
login_page.enterUserName("***");
Thread.sleep(2000);
login_page.clickPass();
login_page.enterPassword("***");
login_page.clickLoginButton();
}
}
After running the code, I am getting the following error:
java.lang.NullPointerException
at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:69)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
at com.sun.proxy.$Proxy9.click(Unknown Source)
at MYQC_Browser_Pages.MYQC_Login_Page.clickUserName(MYQC_Login_Page.java:30)
at MYQC_TestCase_Classes.TC003_MYQC_Prepaid_Login_Test.MYQC_Login(TC003_MYQC_Prepaid_Login_Test.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1198)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1123)
at org.testng.TestNG.run(TestNG.java:1031)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)
your username element is not found on your 3rd test, please do following actions
at MYQC_Browser_Pages.MYQC_Login_Page.clickUserName(MYQC_Login_Page.java:30)
Please add screenshot just before entering username,
Add wait time to load website completely.
still not helpful,
better you should isolate all your test methods.
no static properties
login and logout should be in before method and after method - test method should be independent
use common method for assertions so whenever get failed, automatically add screenshot

java.lang.NullPointerException error on Page Object Model with cucumber

I am getting java.lang.NullPointerException while following Page Object Model with Cucumber. I am not sure what I am doing wrong here, please help me on this
Below is my Test Base Class:
package com.qa.util;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class TestBase {
public static WebDriver driver;
public static Properties prop;
//public WebDriver initializeWebDriver() throws IOException
public static void initializeWebDriver() throws IOException
{
prop = new Properties();
FileInputStream fis = new FileInputStream("D:\\Automation\\WebAutomation\\src\\main\\java\\com\\qa\\config\\config.properties");
prop.load(fis);
String browserName = prop.getProperty("browser");
//Execute in Chrome
if(browserName.equals("Chrome"))
{
System.setProperty("webdriver.chrome.driver","D:\\Drivers\\chromedriver.exe");
driver=new ChromeDriver();
//driver.manage().window().maximize();
}
//Execute in FireFox
else if(browserName.equals("Firefox"))
{
System.setProperty("webdriver.gecko.driver","D:\\Drivers\\geckodriver-v0.19.1-win64(1)");
driver = new FirefoxDriver();
}
driver.manage().window().maximize();
driver.get(prop.getProperty("appURL"));
driver.manage().timeouts().pageLoadTimeout(TestUtil.PAGE_LOAD_TIMEOUT,TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(TestUtil.IMPLICIT_WAIT, TimeUnit.SECONDS);
return driver;
}
}
Below is my login page Objects Class
package com.qa.pages;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import com.qa.util.TestBase;
public class LoginPage extends TestBase {
public LoginPage() {
/*super(driver);
this.driver=driver;*/
PageFactory.initElements(driver, this);
}
// Login Page Title
public String validateLoginPageTitle() {
return driver.getTitle();
}
// Welcome text
#FindBy(css=".login-form > h2:nth-child(1)")
WebElement header;
public String loginPageHeaderText() {
return header.getText();
}
}
Below is my Step Def
package com.qa.stepdefinations;
import java.io.IOException;
import org.testng.Assert;
import com.qa.pages.LoginPage;
import com.qa.util.TestBase;
import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class LoginStepDef extends TestBase {
LoginPage LoginPage = new LoginPage();
#Given("^I launch browser and access the GE URL$")
public void i_launch_browser() throws IOException {
TestBase.initializeWebDriver();
}
#Then("^I am on Login Page$")
public void i_am_on_login_page() {
String expectedLoginPageTile = prop.getProperty("LoginPage_Title");
String actualLoginPageTitle = LoginPage.validateLoginPageTitle();
Assert.assertEquals(actualLoginPageTitle, expectedLoginPageTile);
}
#Then("^I verify header text is displaying$")
public void i_verify_header_text_is_displaying() {
String expectedHeaderText = prop.getProperty("LoginPage_Expected_Header");
String actualdHeaderText = LoginPage.loginPageHeaderText();
Assert.assertEquals(actualdHeaderText, expectedHeaderText);
}
}
The script is working fine for LoginPage.validateLoginPageTitle(); however, I am not sure why it is not working for the next step i.e. LoginPage.loginPageHeaderText();
It seems issue is with your locator, check if it is correct.
#FindBy(css="<b><em>.login-form > h2:nth-child(1)</em></b>")
WebElement header;

Missing return statement, how can I fix?

Goal: I have a class called "InvokeChromeTest" I'm extending to another class called "Base" to access chromedriver and data.properties. When running my code, I get the error:
Error:(22, 3) java: missing return statement
I am unsure how to fix this. Here is my sample code as follows. Please let me know what I can do to fix.
src/test/java/loginPage/InvokeChromeTest
package loginPage;
import credentials.ProfileCredentials;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;
import resources.Base;
public class InvokeChromeTest extends Base {
#Test
public WebDriver initializeDriver() {
driver = initializeDriver();
driver.get(dataProperties.getProperty("url"));
ProfileCredentials p = new ProfileCredentials(driver);
p.getAuthorize().click();
p.getApiKey().sendKeys("testKey");
p.getAuthCred().click();
p.getCloseAuth().click();
}
#AfterTest
public void teardown() {
driver.close();
}
}
src/main/java/resources/Base
package resources;
import io.github.bonigarcia.wdm.WebDriverManager;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Base {
public WebDriver driver;
protected Properties dataProperties;
public WebDriver initializeDriver() {
// Create global property file
dataProperties = new Properties();
InputStream dataPropertiesInputStream = null;
try{
dataPropertiesInputStream = getClass().getClassLoader().getResourceAsStream("data.properties");
dataProperties.load(dataPropertiesInputStream);
} catch (IOException e) {
e.printStackTrace();
}
String browserName = dataProperties.getProperty("browser");
System.out.println(browserName);
if (browserName.equals("chrome")) {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
} else if (browserName.equals("firefox")) {
WebDriverManager.firefoxdriver().setup();
driver = new FirefoxDriver();
}
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
return driver;
}
}
src/main/java/credentials/ProfileCredentials
package credentials;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class ProfileCredentials {
WebDriver driver;
public ProfileCredentials(WebDriver driver) {
this.driver = driver;
}
private By authorize = By.xpath("//button[#class='btn authorize unlocked']");
private By apikey = By.xpath("//div[#class='wrapper']//section//input");
private By authorizecred = By.xpath("//button[#class='btn modal-btn auth authorize button']");
private By closeauth = By.xpath("//button[#class='btn modal-btn auth btn-done button']");
public WebElement getAuthorize() {
return driver.findElement(authorize);
}
public WebElement getApiKey() {
return driver.findElement(apikey);
}
public WebElement getAuthCred() {
return driver.findElement(authorizecred);
}
public WebElement getCloseAuth() {
return driver.findElement(closeauth);
}
}
I figured out the problem. "Base" and "InvokeChromeTest" had the same method name. This is why it was recursive.

How to test or verify check box is selected or not selected by using selenium webdriver java

How to test or verify check box is selected or not selected by using selenium webdriver java
package newpackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
//import org.openqa.selenium.firefox.*;
import java.util.concurrent.*;
public class Qemr { public static void main(String[]args){
System.setProperty("webdriver.gecko.driver","D:\\geckodriver-v0.10.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
String baseUrl = "http://192.168.1.3:9091";
driver.get(baseUrl);
WebElement chkPersist = driver.findElement(By.name("remember"));
chkPersist=click();
for(int i=0;i<2;i++){
System.out.println("chkPersist.isChecked()");
}
}
}
yes there are methods available which you can use for ny kind of controls, for eg. for check box you can use isSelected() method which returns boolean value i.e. 0/1
for your scenario
package newpackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
//import org.openqa.selenium.firefox.*;
import java.util.concurrent.*;
public class Qemr {
public static void main(String[]args)
{
System.setProperty("webdriver.gecko.driver","D:\\geckodriver-v0.10.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
String baseUrl = "http://192.168.1.3:9091";
driver.get(baseUrl);
WebElement chkPersist = driver.findElement(By.name("remember"));
//chkPersist.click();
if(chkPersist.isSelected())
{
System.out.println("Check box is Selected..");
}
}
}
driver.findElement("").isSelected() option is there to check whether Checkbox is selected. you can find solution in your updated code:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
//import org.openqa.selenium.firefox.*;
import java.util.concurrent.*;
public class StackOverFlow1
{
public static void main(String[]args)
{
System.setProperty("webdriver.gecko.driver","D:\\geckodriver-v0.10.0-win64\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
String baseUrl="http://192.168.1.3:9091";
driver.get(baseUrl);
boolean chkPersist=driver.findElement(By.name("remember")).isSelected();
if(chkPersist)
{
System.out.println("chkPersist is in selected state");
}
}
}
}
Question : How to test or verify check box is selected or not selected by using selenium webdriver java.
Answer : Yes we can verify webelement is selected or not using isSelected() method
package newpackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
import java.util.concurrent.*;
public class Qemr {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "D:\\geckodriver-v0.10.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
String baseUrl = "http://192.168.1.3:9091";
driver.get(baseUrl);
WebElement chkPersist = driver.findElement(By.name("remember"));
// Verify chkPersist element is Selected or Not ?
if (chkPersist.isSelected()) {
// if chkPersist element is selected then we print message
System.out.println("chkPersist element is already selected");
} else {
// if chkPersist element is not selected then we select / click on chkPersist element
chkPersist.click();
}
}
}

Automated testing using selenium with firefox browser

I downloaded the code below and used it for some tests and u=it ran yesterday but since today the code stopped working. My tests are failing now which was not happening before. It throws up an error saying org.openqa.selenium.ElementNotVisibleException: element is not currently visible so cannot interact with element.
package org.openqa.selenium.example;
//import org.openqa.selenium.browserlaunchers.locators.GoogleChromeLocator;
//import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
//import org.openqa.selenium.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
//import org.openqa.selenium.chrome.*;
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.firefox.FirefoxDriver;
//import org.openqa.selenium.support.ui.Select;
//import org.openqa.selenium.net.UrlChecker;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class KongaUrlTest
{
private WebDriver driver;
private String baseUrl;
//private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
#Before
public void setUp() throws Exception
{
driver = new FirefoxDriver();
baseUrl = "http://www.konga.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void testFirefoxWebdriver() throws Exception
{
driver.get(baseUrl);
driver.findElement(By.cssSelector("a.vertnavlink > span")).click();
try
{
assertEquals("Phones & Tablets | Konga Nigeria", driver.getTitle());
System.out.println(driver.getTitle());
}
catch (Error e)
{
verificationErrors.append(e.toString());
}
}
#After
public void tearDown() throws Exception
{
System.out.println(driver.getCurrentUrl());
driver.quit();
}
}
There's a blocking dialog being displayed. It's probably displayed each time Selenium opens a new browser and navigates to that site. Close that dialog first:
driver.get(baseUrl);
try
{
driver.findElement(By.cssSelector(".fancybox-close")).click();
}
catch { }
driver.findElement(By.cssSelector("a.vertnavlink > span")).click();

Categories