I'm using Selenium WebDriver (Java) and am trying to change the URL after WebDriver has logged into a page.
Is there a way to either:
Change the URL of the current window, or
Open a new tab and go to another page.
Thanks!
You didn't share any code so i don't know how is your approach about it, I only share my knowledge about this subject.
1) For your first question i think you know how to open a new page with selenium web driver maybe you can use some wait method and then invoke the driver again.
//open browser
driver = new FirefoxDriver();
//login
driver.get("https://www.google.com/");
//set implicit wait
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//Then invoke method again for your second request(I am not try this code maybe you need to create new driver object)
driver.get("https://www.stackoverflow.com");
2) For your second question this link help you.
Related
I want to allow the Pop-ups and redirect setting of chrome using selenium java. Is there any way?
In pop-ups logic we have to mention below logic,
WebDriver driver = new ChromeDriver();
String url = " https://www.google.com";
driver.get(url);
For more clarification please gothrough the link1 first example
How to know WebDriver opened an URL successfully after driver.get(appURL)? I can see it opens nicely in a browser. But I would like to make sure programmatically.
Hey. Here I am asking whether driver.get(appURL) returns any response code like http response. Or I have to find a ID from the web page and find it, then make conclusion, but the approach seems too primitive. I am looking for more simple solution. Someone suggested assertTrue, but some reason Eclipse is giving long error.
The simplest way to do so, would be to assert over the page title of the url you have opened :
String actualTitle = driver.getTitle();
String expectedTitle = "YourExpectedPage"; // replace with the expected page title
org.junit.Assert.assertTrue(expectedTitle.equals(actualTitle));
you can wait some time and check expected result then check current url
String currentURL = null;
WebDriverWait wait = new WebDriverWait(driver, 10);
if(driver.findElement(By.xpath("//*[#id='someID']")).isDisplayed()){ //add id or xpath
currentURL = driver.getCurrentUrl();
System.out.println(currentURL);
}
Each browser has a default error page. For chrome i am using:
if(driver.findElement(By.xpath("//div[#class='error-code']")).isDisplayed()){
MessageBox.Show("chrome error page.");
}
Try this with simple statements
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
String baseUrl="https://stackoverflow.com/";
driver.get(baseUrl);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
if(baseUrl.equals(driver.getCurrentUrl()))
{
System.out.println("URLS are matching");
}else
{
System.out.println("URLS are not matching");
}
As a End User we really don't have to be concerned about whether WebDriver instance opened an URL successfully or not because once the WebDriver instance requests for a URL, the Browser Client on opening the webpage/website (by default) returns document.readyState as complete to the WebDriver instance and only then our next line of code gets executed.
However, as an End User we can configure the WebDriver instance to act on different available states of the DOM as well. Currently Selenium recognizes document.readyState at 3 different stages as follows:
none - The document is still loading
eager - The document is interactive
normal - The document is complete
Hence our scripts can be written to configure the WebDriver instance to respond as per your requirement.
I have a scenario as below
1. Login to the application
2. click on a button (say Buy)
3. This will take me to a new window opened with a new URL automatically
4. Perform actions in the new window
5. Quit
Kindly please provide the exact code to work on this. I tried with the available code that exists in the website which didnt work for me
You can try on following pattern:-
Webdriver driver = new ChromeDriver();
driver.get("URL of application");
driver.findElement(By.id("username").sendKeys("user1");
driver.findElement(By.id("password").sendKeys("pass1");
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
driver.findElement(By.xPath("xpath of button").click();
//now you can switch to pop-up and accordingly accept or dismiss it
driver.switchTo().alert().accept();
driver.quit();
In case you provide the SO community the URL of application then only complete code can be provided.
I'm stuck on how can I open the instance of webdriver on my html page using java.
WebDriver driver = new ChromeDriver(); // Open the Application
the code below open the instance of driver chrome.
If you want to start chrome browser, first download chromeDriver from here After that we need to specify this downloaded chromedriver and then start the driver instance
System.setProperty("webdriver.chrome.driver", "\\downloaded driver path");
WebDriver driver = new ChromeDriver();
driver.get("http://URL here/");
Then as said need to switch to frame, so
driver.switchTo().frame("iframe id or name");
//or
driver.switchTo().frame("index like 0, 1");
//or
driver.switchTo().frame(driver.findElement(By.xpath("//iframe"))); //iframe location
//after work in frame is completed, then we need to switch back to default content
driver.switchTo().defaultContent();
Thank You,
Murali
We are testing an application build using Telerik.
A demo of Telerik is available here: http://demos.telerik.com/aspnet-ajax/window/examples/radwindowobject/defaultcs.aspx
Our application is build in a similar way.
In this demo you can see a window with Bing in it. I want to switch to it using WebDriver (Java) to perform actions on objects within it.
I have tried to switchto iframe but WebDriver comes back saying it is not an iframe.
Also tried to get window handles and switchto window but with no luck, it is not treated as a new window. Any suggestions please?
The following code worked for me. I was able to enter text in the bing search field.
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://demos.telerik.com/aspnet-ajax/window/examples/radwindowobject/defaultcs.aspx");
driver.switchTo().frame("RadWindow1");
driver.findElement(By.name("q")).sendKeys("Hello this is my text");
Let me know if this helps you.