I need to switch tabs using Graphene and continue the test without failing.
I am testing an application that creates a project and then opens that project from a link on a page.
My issue is that it opens the project in a new tab and to continue the test I have to switch to the new tab.
I am using the selenium switch windowHandler but getting an error from the Graphene. I will not know the new URL until the project has been created.
//Switch to tab opened from previous test
public void switchTab(int tabNumber) throws Exception{
for (String winHandle : driver.getWindowHandles()) {
driver.switchTo().window(winHandle);
Thread.sleep(3000);
}
}
Error: The page object 'CreateChangeSubProjStruct' that you are navigating to using either Graphene.goTo() or #InitialPage is not annotated with #Location
I can see the new page opens and is on top but the test is running on the original tab.
Related
I have a Web application to automate using selenium and Java.
Application supports IE Browser on windows10 and for windows11 we have created an .lnk file to open same application in Edge browser because IE is no longer. And we have some videos to be streamed in application for which media player to be installed and more.
Scenario :
I have to open ABC.lnk application from desktop
Once clicked on ABC.lnk application, our application will open in Edge browser.
for step 1 : using below code to open ABC.lnk application
public static void openWindowApplication() {
String command = "C:\\Users\\Kasper\\Desktop\\ABC.lnk";
try {
Runtime.getRuntime().exec("cmd /c " + command);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Step 2 :
Edge driver initialization Code :
System.setProperty("webdriver.edge.driver", FileReaderManager.getInstance().getConfigReader().getDriverPath() + "/msedgedriver.exe");
//Creating an object of EdgeDriver
driver = new EdgeDriver();
driver.manage().window().maximize();
//Deleting all the cookies
driver.manage().deleteAllCookies();
//Specifiying pageLoadTimeout and Implicit wait
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
I have used above code to achieve above scenarios. But 2 edge browsers are getting open and nothing is happening because of above code snippet and Step 1 is required to open ABC.lnk and application opens in edge browser on click on it.
And I have to perform automation on open browser through ABC.lnk click.
How can I perform automation in same edge browser open in step 1.
Thanks in advance.
I am working on Desktop application using WinAppDriver and Selenium C#.
There are couple of links on the application.
If we click on the link, it will redirect to default browser.
How I can switch focus from WinAppDriver to IWebDriver ?
How to verify the link, whether the link opened in default browser or not?
Please help on this. Thank you.
// Switch to new window opened
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
// Perform the actions on new window
// Close the new window, if that window no more required
driver.close();
// Switch back to original browser (first window)
driver.switchTo().window(winHandleBefore);
I am using IE11 for my selenium tests. I Am clicking on a link which when done manually opens up the link on a new tab.
When I am trying to do the same thing with Selenium, it does not open the link on a new tab rather, it opens up on a new window.
Is there a way to force IE to click and open the link on a new tab?
I am able to achieve the same with Firefox and Chrome, but with IE, as soon as the link is clicked, it opens on a new window rather than a new tab.
if (BROWSER_TYPE.equals("IE")) {
Utility.log(this.getClass().getName(),Level.INFO,"Browser type is IE downloading firefox driver is required.");
WebDriverManager webDriverManagerObject = WebDriverManager.iedriver();
webDriverManagerObject.targetPath(DRIVER_DOWNLOAD_PATH);
if(!DRIVER_VERSION.equals("latest")) {
WebDriverManagerObject = webDriverManagerObject.version(DRIVER_VERSION);
}
Utility.log(this.getClass().getName(),Level.DEBUG,"Launching IE Browser");
webDriverManagerObject.setup();
driver = new InternetExplorerDriver();
}
Expected Result: Clicking on the Link should open the page on a new tab on the same window in IE
Actual result: Clicking on the Link opens the page on a new window rather than a new tab.
I'm trying to write a piece of code using Testng in selenium, the problem is when i try to click a link, the code becomes unresponsive and gives error- Timed out receiving message from renderer
Tried driver.get("https://infostore.saiglobal.com/") instead of driver.findElement(By.linkText("Infostore")).click(); still remains unresponsive - Doesnot get directed to the webpage - https://infostore.saiglobal.com/
#Test
public void testSai() throws Exception {
driver.get("https://www.saiglobal.com/"); //open homepage
driver.findElement(By.id("CybotCookiebotDialogBodyButtonAccept")).click(); //accept cookie
driver.findElement(By.cssSelector("#sai-header > div > div.main-nav > div.store-box > div")).click(); //click on Login to open list
sleep(2);
driver.findElement(By.linkText("Infostore")).click(); //click on infostore to be redirected to https://infostore.saiglobal.com/
System.out.println(driver.getCurrentUrl());
Yes I have checked this issue and there is an workaround for this issue if you wish to have this.Try following code.
Take the href attribute value from the link element.
Delete all cookies.
driver.navigate().to(URL);
public static void main(String[] args){
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + File.separator + "\\Executables\\Chromedriver.exe");
WebDriver driver = new ChromeDriver();
WebDriverWait wait = new WebDriverWait(driver, 5);
Actions actions = new Actions(driver);
driver.get("https://www.saiglobal.com/");
driver.findElement(By.id("CybotCookiebotDialogBodyButtonAccept")).click();
WebElement element=wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[#class='desktop-login']")));
actions.moveToElement(element).build().perform();
WebElement element1=wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[#class='desktop-login']/ul/li/a[contains(text(),'Infostore')]")));
String str1=element1.getAttribute("href");
driver.manage().deleteAllCookies();
driver.navigate().to(str1);
System.out.println(driver.getCurrentUrl());
}
This seems to be an error with Selenium that the developers have been dealing with for over a year. They never really give a concrete answer as to what causes it or how to fix it.
The first port of call would be to make sure that your browser and Selenium are compatible. Try opening a different URL that you know works, and if the error persists then there is likely an error with the compatibility of your selenium and web browser. If it works, then there is something wrong with your website.
For reference, I opened your website using Python Selenium, and had no issues loading or interacting with elements. So the error is local to the software you are using.
The issue can also be caused by sleeps(no idea why), so try removing any sleeps and see if this stops the issue.
I have a login page which redirects to a page from where I need to extract some data from an element using selenium.
I am running the code from local eclipse using the IE driver but facing an issue as the pagesource is that of the initial web driver page after some time the IE browser does navigate to the page with some delay , but the page source remains the same and get a exception as no such element found.
Have tried to add implicity waits but did not work.
Any work around where I can induce a delay ?
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
caps.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
caps.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
File file = new File("D:/IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
driver = new InternetExplorerDriver(caps);
driver.get(baseUrl);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().setSize(new Dimension(600, 600));
Based on your comment (to your question) that "It does not navigate beyond the first page of the driver having title 'WebDriver'", I gather you are not able to go to login page, enter credentials and click on some button that will redirect to 2nd page.
In that case, please make you that you are using appropriate version of Internet Explorer driver. I am using 64-bit version of Internet Explorer driver as I am using 64-bit version of Internet Explorer browser and 64-bit OS on my PC. If you are using 32-bit version of Internet Explorer browser and 32-bit OS, you will need to use 32-bit version of Internet Explorer driver. How to find which version of Internet Explorer browser we are using: By checking path of it's executable file, whether it is in "Program Files" or in "Program Files (x86)" folder. How to see whether OS is 32 bit or 64 bit: Right-click on "Computer" and select "Properties".
I think following code would work:
#BeforeTest
public void setup() {
System.setProperty("webdriver.ie.driver", "C:/Dependancies/IEDriverServer.exe");
driver = new InternetExplorerDriver();
}
#Test
public void test() throws InterruptedException {
driver.get("URL_of_login_page"); // Make sure the URL begins with 'http' or 'https'.
// Enter login credentials, click on 'Submit' button so that it will redirect to 2nd page.
Thread.sleep(15000); // Assuing 15 seconds is sufficient time for the 2nd page to load.
System.out.println("The 2nd page is loaded now.");
System.out.println(driver.getTitle()); // It should print page-title of 2nd page.
String source;
source = driver.getPageSource();
System.out.println(source);
}