java - WebDriver PhantomJS Unable to find element, but works fine with Firefox -


I have been ringing my head in the wall for a long time, so I thought I would ask "experts" why down Code will not work with PhantmJs (entering password), but works fine with Firefox. The most upsetting thing is that a field entry (username) is successful, but no one else will work. Page load is fine and I've included a test code to verify other components. Has been properly loaded.

Look at the code below:

  import java.io.File; Import org.openqa.selenium *; Import org.openqa.selenium.firefox.FirefoxDriver; Import org.openqa.selenium.phantomjs.PhantomJSDriver; Public class login {public static zero main (string [] args) {WebDriver driver; Boolean verbose = false; // Change it to the right to test with Firefox string fontpath = "../phantomjs-1.9.8-linux-i686/bin/phantomjs"; String url = "https://www.britishairways.com/travel/redeem/execclub/_gf/en_us"; If (verbose) {driver = new firefox driver (); } Other {file file = new file (phantom); String UserEgent = "Mozilla / 5.0 (Windows; U; Windows NT 5.1; CS; RV: 1.9.0.8) Gecko / 200 9 032609 Firefox / 3.0.8"; System.setProperty ("phantomjs.binary.path", file.getAbsolutePath ()); System.setProperty ("phantomjs.page.settings.userAgent", User Agent); Driver = new funmzsdriver (); } Driver.get (url); Try {Driver.findElement (By.id ("membership number")). SendKeys ("1234"); System.out.println ("ID input successful"); If (driver.findElement (By.id ("ecuserlogbutton") isDisplayed ()) {System.out.println ("login button exists"); } // This is where it fails with the PhantomJS, but works with the Firefox driver.Fed Element (by.cssSelector ("# pintr> #password")). SendKeys ("1234"); System.out.println ("Password input successful"); } Hold (exception e) {System.out.print (e.getMessage ()); } Driver.close (); }}  

There is a problem with element ID in PhantomJS 1.x The site is broken , Because it uses password for two elements on the page that should never be. By changing the ID in the selector with just the element type ( input ), it is resolved.

  driver.findElement (by.cssSelector ("#pintr"; input ")) .sendKeys (" 1234 ");  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -