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).