0

I have java code for one of my automation website and I copy that code to other PC to run other Website however the first step is running ok which is open the URL but the rest can not be run , unable to locate the element id , here is the code in Java:

@When("^I enter (.*) in the (.*)$")
public void i_enter_in_the_Username_txt_box(String emailaddress,String boxname) throws Throwable {
 WebDriverWait wait = new WebDriverWait(driver,LOAD); 
  By id = By.id(boxname);
wait.until(ExpectedConditions.elementToBeClickable(id));
driver.findElement(By.id(boxname)).sendKeys(emailaddress); 
}

BDD for this code is :

Feature: XYZ

Scenario: Add valid username and password then click on login button

Given User at login page // this one is working fine 
When I enter Admin in the username // this one is not working , error saying that the Id for the username field can not find 
And  I enter Admin in the password
Then Home page will display

Would you please let me now if you know where is the issue ? I tried the following but still i got the error :

  1. Add Thread.sleep(1000); to wait but still i got the error
  2. I added "" for the Admin and the Id for the field in the BDD file but still it did not work

I am using cucumber , Firefox , selenium , Eclipse , BDD, Maven and Java Thanks a lot

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190

2 Answers2

0

Try change this driver.findElement(By.id(boxname)).sendKeys(emailaddress); to driver.findElement(id).sendKeys(emailaddress);

Ranjith's
  • 4,508
  • 5
  • 24
  • 40
  • there's no difference in that..either we use By.id or use object of it – Mrunal Gosar May 23 '16 at 15:10
  • id is correct as OP says its running on one machine – Mrunal Gosar May 23 '16 at 15:19
  • I suspect it could maybe just have something to do with Firefox version. Can you please try switching the browser flavor to chrome (or) IE and see if that works ? [ Unlike chrome and IE which are driven by external binaries, firefox has a tight coupling on the Selenium version that it works with ]. Also please help share the exact exception stacktrace – Krishnan Mahadevan May 24 '16 at 03:07
0

I found couple of issue. I am not clear what error you are getting that's reason I am trying to debug multiple way.

Feature: XYZ

Scenario: Add valid username and password then click on login button

Given User at login page // this one is working fine 
When I enter Admin in the username // this one is not working , error saying that the Id for the username field can not find 
And  I enter Admin in the password
Then Home page will display

This is not correct. Given statement will work because you are not passing any value as parameters from statement to step definition.

It is failing here When I enter Admin in the username

because you didn't add parameter well.

I think you can do this way

When I enter "stack@stack.com" in the "username"

Currently It will take two user parameters as per your step definition requirement.

I am expecting "username" is your box name.

other reason could :

WebDriverWait wait = new WebDriverWait(driver,LOAD);

Are you sure you are getting driver and LOAD in step definition ?

N..
  • 906
  • 7
  • 23