4

I have to create a demo for a new web-application using Selenium Webdriver Java, this demo is being created for a client meeting (as to show him, compatibility of Selenium with their application). But my bad luck I got stuck on the very login page. I have to use client provided machine for this (so I am not the administrator of the system).

The issue is when I try to log in manually, I am able to log in without any problem, but when I fire the same steps using Selenium Webdriver, it is hitting the login button but processing stops after 1-2 seconds (tried many times).

In place of .click(), I have tried sendKeys(Keys.ENTER) and sendKeys(Keys.RETURN). Also, I have tried launching Firefox with different user profiles too like this

ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("abc.Default User");
WebDriver driver = new FirefoxDriver(myprofile);

but these solutions are not working. I tried the same kind of scripting on other applications (like Gmail, Flipkart etc.) and they are working fine.

Additional information:

  1. I know that there is some kind of javascript which is fired on clicking of the login button which is required for login (but have found that with other tools like Test Studio, VSTS Coded UI and Selenium IDE this case is working fine for this application).
  2. Even after using a different profile (as mentioned in the mode above), Firefox instance launched by Selenium is different then when it is manually launched. But I have tried with different profiles.
  3. Have tried after converting Selenium IDE code into the WebDriver but still same issue.
4
  • I have faced same issue many time , Did you try same website for login via selenium webdriver in another machine? Oct 21, 2015 at 3:22
  • No, I didn't tried another machine. But yes, this is a good suggestion and will take it. Thanks
    – Dhiman
    Oct 21, 2015 at 13:05
  • Sure , please try... Oct 22, 2015 at 3:02
  • I also faced the same problem, I have waiting time also but sometimes it works and sometimes not.
    – sachin
    Oct 30, 2017 at 6:33

2 Answers 2

3

If the login form is 'hijacked' via JavaScript your test might be running too fast. So if you open the url, enter values, and submit it won't work. You can try adding a 'pause' for 1500ms after opening the page to give the JS time to load (as a test of this theory). To submit the form a click() on the button should work. You could also try 'submit' form.

2
  • You are absolutely right, I had already added wait time for 2 secs before Clicking the Login button and after entering Username and Password and test case worked. Just was looking for someone to answer, if this is the correct approach ;-)
    – Dhiman
    Oct 21, 2015 at 19:01
  • An explicit wait isn't ideal, but if there isn't something to waitFor, then your hand is pretty much forced. Using 'pause' means it could wait longer than it needs (or not long enough on slow machines). These can also compound in such a way that you test spends most of it's time pausing. So use it sparingly.
    – kirbycope
    Oct 21, 2015 at 19:05
1

I also faced a similar problem with my application. Clicking the element through action class worked for me.

WebElement webElement = driver.findElement(By.id("Your ID Here"));
Actions builder = new Actions(driver);
builder.moveToElement(webElement).click(webElement);
builder.perform();

If clicking with action class does not work, you can also try clicking element by Javascript.

WebElement webElement = driver.findElement(By.id("Your ID here"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", webElement);

Not the answer you're looking for? Browse other questions tagged or ask your own question.