I'm trying to send text to the password field at https://signup.live.com/ however while all other fields are populated correctly (and the XPath for password field is also correct -- .//*[#id='Password']) the data doesn't show up for in the password and password confirmation fields.
I have a feeling it has to do with the fact that after sending email/user name the page (sort of) refreshes (it displays "this username is available" or "unavailable") but this only effects the password fields..
I am not sure how to resolve the issue as the XPath I'm using is correct..
Any ideas?
Thanks
P.S
Some people say the email validation is causing the error which is probably correct. However when I add:
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
it does not seem to fix the issue. Sometimes it works, most of the time it doesn't.
It causing problem due to email validation. Once you send an email the site validates and selenium tries to send password meanwhile but couldn't find the element focused and throws So it couldn't focus on password field and throws :
Exception in thread "main" org.openqa.selenium.WebDriverException:
unknown error: cannot focus element
So before sending password you have to put some wait until the emailid get validated (analyze how much time it takes to validate email) and then send your password. Here Thread.sleep() will help you to do so. but some time its not recommended because it pause your script for given time event your element intractable before given time.
Another recommendation is if you have element id then avoid to use xpath you can locate same like driver.findElement(By.id("Password")).
For your script sample code can be :
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://signup.live.com/");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.id("FirstName")).sendKeys("test");
driver.findElement(By.id("LastName")).sendKeys("user");
driver.findElement(By.id("MemberName")).sendKeys("testuser#gmail.com");
Thread.sleep(10000);
driver.findElement(By.id("Password")).sendKeys("testone1#");
driver.findElement(By.id("RetypePassword")).sendKeys("testone1#");
Related
I'm writing a web page in Spring Boot and using Selenium to get data from another website based on user's action, which means Selenium will get data on the fly. The website will require login to get the data. So the website will first need to initiate the webDriver and log in (I'm using user-data attribute but sometimes the login will expire so need to check every time). I'm trying to find the best approach for using Selenium to get data on the fly. From what I have experienced, if I use something like this to initialize Selenium driver:
try {
webDriver.get(url);
WebDriverWait wait = new WebDriverWait(webDriver, Duration.ofSeconds(TIME_OUT));
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("button")));
logger.info("Already logged in");
} catch (TimeoutException e) {
logger.error("Not logged in yet");
login(webDriver);
}
The "button" here will only be present if it is logged in. I added a log above and after this line and found out it will take about 8 seconds to finish this part, which is too long. I initially added this when user triggers the action, but this will obviously be too long.
My thought to overcome this is: for each connection, once user hits the website main page (does not need Selenium at main page) then start creating a new instance of webDriver and the login process and hold the webDriver for each of the connections. But how should I approach in such a way? Should I use Spring boot HttpSession and do something like:
session.setAttribute("driver", webDriver);
And then later if user actually makes the request that needs Selenium, then it can retrieve the webDriver using
session.getAttribute("driver");
Is this something that is reliable to use?
Or could anyone please enlighten me on how should I optimize this?
Thanks a lot!
I have a Wicket 8.6 application. Currently, when logging in to the application, mostly (does not always happen) the user has to login twice. After the first login (after entering the credentials and clicking the submit button) a white page appears saying "If you see this, it means that both javascript and meta-refresh are not support by your browser configuration. Please click this link to continue to the original destination." This is the BrowserInfoPage. After a few seconds the user is redirected to the login page again where he/she has to enter his/her credentials again and press the login button. This time, the user logs in successfully. My question is, how do I prevent that the user hast to enter his/her credentials twice.
From my research I know that it has something to do with the collection of extended browser info. In the init method of my WicketApplication class, I had the following code:
getRequestCycleSettings().setGatherExtendedBrowserInfo(true);
However, I already commented out this code several month ago. For some reason, the described effect occurs for every new deploy now. Maybe a newly added package in the application is the reason for it. I don't know. Is there a possibility to prevent this second login maybe by creating a customized bowser info page which forwards the login? Please point me in the right direction. Thanks.
After some research, I came up with a work around. It is probably not very efficient but it works for me so far. In my custom Session class which inherits from AuthenticatedWebSession, I added the following code.
#Override
protected WebPage newBrowserInfoPage() {
final Request request = RequestCycle.get().getRequest();
if(request.getUrl().toString().contains("LoginPage")) {
if(!isSignedIn()) {
signIn(username, password);
}
PageParametersEncoder encoder = new PageParametersEncoder();
PageParameters parameters = encoder.decodePageParameters(request.getUrl());
String url = parameters != null && parameters.get("originUrl") !=null && !parameters.get("originUrl").isNull() && !parameters.get("originUrl").isEmpty()?
parameters.get("originUrl").toString("pages/home"):"pages/home";
String finalUrl=url.startsWith("pages/")?url.substring("pages/".length()):url;
throw new RedirectToUrlException(finalUrl);
}
return super.newBrowserInfoPage();
}
Some explanation to the code. As mentioned in the question, I want to prevent the user from logging in multiple times. Thus, I check if the request comes from the LoginPage and perform my work around only in that case.
During my implementation, I realized, that the method newBrowserInfoPage is called in the process when I call session.signIn(username,password); on my LoginPage. In this signIn process the authenticate method of my custom Session is called but the signedIn flag in the AuthenticatedWebSession is not changed (keeps false on successfull authentication). Is this a bug? Thus, I have to login again to set the flag to true.
Finally, I read the URL of the LoginPage where I have stored the target URL and forward the user to the target URL.
I am aware this is probably not the best approach but it is the only solution I came up with. If someone has a better idea, I am happy to hear it.
I am getting an [object Object] error when I try to automate a web page.I am using Firefox v39 as later version cause problems in online signature. My code did work properly for Firefox v63.
Code is simply to open a webpage, enter username and password, login, and then navigate to a page.
I have provided a Screenshot of the error. Please check.
enter image description here
CODE-
System.setProperty("webdriver.firefox.marionette","F:\\firefoxdriver\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("LINK");
driver.manage().window().maximize();
driver.findElement(By.id("username")).sendKeys("USERNAME");
driver.findElement(By.id("password")).sendKeys("PASS");
driver.findElement(By.xpath("//button[#class='btn btn-success btn-logging']")).click();
WebElement kyc =driver.findElement(By.xpath("/html/body/div[1]/div/div/ul/li[2]/ul/li[6]/a"));
String href=kyc.getAttribute("Href");//get link to approval
driver.navigate().to(href);
This happens when the page is not completely loaded and hence an object is not found. This could happen due to slow net, slow site.
Solution-
Increase the wait, used static wait and keep increasing it unless it does not occur.
I am actually new to selenium web driver and stackoverflow. I am working on automating test cases for a 'forgot password' feature which has a dialog box when unregistered email address is entered.
I want to validate the message 'This email is not registered!' in the dialog box ,but not sure how to proceed as i am using xPath which keeps changing for the message 'This email is not registered'.
This email account is not registered!
#Test
public void checkForgotPasswordWithInvalidCredentials() throws Exception {
driver.findElement(By.xpath(".//*[#id='forgetBtn']")).click();
driver.findElement(By.xpath(".//*[#id='emailInput']")).sendKeys("test#test.com");
driver.findElement(By.xpath(".//*[#id='verify_btn']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath(".//*[#id='alert_box_14']/p")).isDisplayed();
}
In the above code, the Xpath for the alert message(.//*[#id='alert_box_14']/p) keeps changing.
Any help would be appreciated. Thanks!
If the number keep changing you can use partial id
driver.findElement(By.xpath(".//*[contains(#id, 'alert_box')]/p")).isDisplayed();
I'm writing a program in Java to automate a web test of server management console URL's to find which ones present users with a box for login credentials.
I have begun looking into doing this with Selenium WebDriver to automate the actual test function of opening and closing windows, but what I can't figure out is how I should go about detecting whether or not the login box is presented to a user.
Is there a specific response code that the server presents when this happens? I know when a user is unauthenticated/forbidden there will be an HTTP response of 401 or 403, respectively, but I am not sure if this 401 unauthenticated response Code will happen regardless of whether or not a box for login credentials is presented to the user.
The goal is to find which URL's allowed a user the opportunity to type in credentials and then publish those to a .txt file for further evaluation. I already have the java I/O elements working properly to do this, so all I really need is to figure out what condition I'm looking for. Any help would be appreciated!
Given you have an instantiated WebDriver instance (driver)
and a collection of URLs (urls) you want to check,
and given your loginbox contains some element located by ID "username"
then one possible Selenium solution in Java could look like this:
for (String url : urls) {
driver.get(url);
//adjust to your needs: long timeOutInSeconds, long sleepInMillis
WebDriverWait wait = new WebDriverWait(driver, 120L, 1000L);
try {
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("username")));
//TODO: Element found within timeOutInSeconds
} catch (WebDriverException e) {
//TODO: Element not present after timeOutInSeconds, write url to txt file
}
}
If you cannot locate the element by id, use other locating mechanisms as described here.