New to Cucumber, executing it along with Selenium. I have written a feature file as where user first goes to a home page then clicks on Register link & verify that the said fields are displayed.:-
The step definition for the same has also been written. But when i execute the feature file .
It shows an error i.e " org.openqa.selenium.JavascriptException: javascript error: Cannot read property 'setAttribute' of null" .
Could anyone help out to solve this issue.
My Feature file scenario is :-
@TC2
Scenario: Verify the Register link provided on Home Page
Given user is on HomePage
When user clicks on register link
Then user should be able to view following <fields> such as
|fields|
|First Name|
|Last Name|
|Address|
|City|
|State|
|Zip code|
|Phone|
|SSN|
|Username|
|Password|
|Confirm|
Step Definition File is as follows :=
@When ("^user clicks on register link$")
public void click_register()
{
WebElement Register_link=driver.findElement(By.xpath("//a[contains(text(),'Register')]"));
Register_link.click();
}
@FindBy(xpath="//table[@class='form2']/tbody/tr/td[2]/input[@id='customer.firstName']")
private WebElement first_name;
@FindBy(xpath="//table[@class='form2']/tbody/tr/td[2]/input[@id='customer.lastName']")
private WebElement last_name;
@FindBy(xpath="//table[@class='form2']/tbody/tr/td[2]/input[@id='customer.address.street']")
private WebElement Address;
@FindBy(xpath="//table[@class='form2']/tbody/tr/td[2]/input[@id='customer.address.city']")
private WebElement city;
@FindBy(xpath="//table[@class='form2']/tbody/tr/td[2]/input[@id='customer.address.state']")
private WebElement state;
@FindBy(xpath="//table[@class='form2']/tbody/tr/td[2]/input[@id='customer.address.zipCode']")
private WebElement zip;
@FindBy(xpath="//table[@class='form2']/tbody/tr/td[2]/input[@id='customer.phoneNumber']")
private WebElement phone;
@FindBy(xpath="//table[@class='form2']/tbody/tr/td[2]/input[@id='customer.ssn']")
private WebElement SSN;
@FindBy(xpath="//table[@class='form2']/tbody/tr/td[2]/input[@id='customer.username']")
private WebElement Username;
@FindBy(xpath="//table[@class='form2']/tbody/tr/td[2]/input[@id='customer.password']")
private WebElement password;
@FindBy(xpath="//table[@class='form2']/tbody/tr/td[2]/input[@id='repeatedPassword']")
private WebElement repeat_pass;
@Then ("^user should be able to view <fields> such as$")
public void verify_fields(DataTable testData)
{
List<String> all_fields=testData.asList(String.class);
for(String fields_links:all_fields)
{
JavascriptExecutor js=(JavascriptExecutor)driver;
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",first_name, "color: blue; border: 2px solid Magenta;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",last_name, "color: blue; border: 2px solid Magenta;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",Address, "color: blue; border: 2px solid Magenta;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",city, "color: blue; border: 2px solid Magenta;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",state, "color: blue; border: 2px solid Magenta;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",zip, "color: blue; border: 2px solid Magenta;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",phone, "color: blue; border: 2px solid Magenta;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",SSN, "color: blue; border: 2px solid Magenta;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",phone, "color: blue; border: 2px solid Magenta;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",Username, "color: blue; border: 2px solid Magenta;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",password, "color: blue; border: 2px solid Magenta;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);",repeat_pass, "color: blue; border: 2px solid Magenta;");
}
JavascriptExecutor is used here to highlight the elements in order to verify it exist.
This is the error message - "org.openqa.selenium.JavascriptException: javascript error: Cannot read property 'setAttribute' of null
".
It is stating that it cannot read any property. No property has been defined here.
Please help me out to solve this query . Unable to find the root cause of this issue.