3

I use PhantomJSDriver with Selenium v.2.1 (latest for this moment) on Linux.

I do login, click on submit button, then my site does redirect (2 times, http 302),and there I try to find the user-name as he/she is logged-in.

  loginButton.click() // will refresh the page

  // TODO: after redirect (302). wait?

  val profileElement = driver.findElement(By.xpath("//*[@id='login_name']"))

So, Q: what is the usual solution for that, how to get element after page-redirect?

UPDATE: (page-reload wait)

I tried to wait:

driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);

By default I do not use any cookies capabilities. I believe it is similar to Chrome' anonymous mode but with Phantom browser.

Same result so far.

UPDATE 2 (wait for particular element):

I've tried to wait for particular element I expect to be after user logged-in:

val waitForProfileNameLink = new WebDriverWait(driver, 10)
waitForProfileNameLink.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='login_name']")))

same with: presenceOfElementLocated

While it waits, i see in the log:

 phantomjs://platform/console++.js:263 in error
[ERROR - 2016-11-20T14:10:37.777Z] WebElementLocator - _handleLocateCommand - Element(s) NOT Found: GAVE UP. Search Stop Time: 1479651037763

many times. I guess that is the way it tries/waits.

UPDATE 3 (update dependencies):

Because I was thinking about this bug, then

as was suggested in Setup section, I got rid of direct dependcy to PhantomJSDriver but instead, downloaded the latest Phantom JS and latest Selenium,

so (org.openqa.selenium.phantomjs.PhantomJSDriver v = 1.3.0, Selenium 3.0.1):

   System.setProperty("phantomjs.binary.path","/home/me/phantomjs/bin/phantomjs")

  implicit val driver: RemoteWebDriver = new PhantomJSDriver()

But still, same issue.

UPDATE 4 - (screenshot)

I did screenshot just after I try to login:

loginButton.click()
driver.manage().timeouts().pageLoadTimeout(50, TimeUnit.SECONDS)
val scrFile = driver.getScreenshotAs(OutputType.FILE)
FileUtils.copyFile(scrFile, new File("/home/me/login.png"))

And that screenshot shows that, actually, I'm still on login page, and it is pending (progress-bar on login button) to login..

Now I think that that particular site somehow behaives differently when I go there with phantomjs or real browser (there some js trigets that stop me being loged-in). What that difference may be? But I guess I know what it is, but seems it goes out of the scope of this question (so I'm closing it).

ses
  • 13,174
  • 31
  • 123
  • 226
  • http://stackoverflow.com/questions/15122864/selenium-wait-until-document-is-ready –  Nov 20 '16 at 05:46
  • 1
    updated: I tried to wait, it seems does not work. maybe the driver still connected with old document, before redirect? Not sure yet. – ses Nov 20 '16 at 13:39
  • 1
    Did you try waiting for appearance of elements? https://selenium-python.readthedocs.io/waits.html#explicit-waits – TheNavigat Nov 20 '16 at 13:59
  • yes, I did try: update2 – ses Nov 20 '16 at 14:04
  • I usually write simple routines that loop. F.I. looping 40 times (max until I make it throw an exception) and wait 250ms then check if an element is present (...findelements.by.--etc--.size()>0 ). This way it is easier to control. I don't know why but the wait commands seem a bit strange sometimes. Also this kind of routine enables you to wait until you are at a certian URL for instance. – Chai Nov 21 '16 at 14:43

0 Answers0