Selenium Select Window command fails and shows "Could not find window with title....". but if i Execute the Select Window command alone it passes the case and verifying the elements.
Code i used:
public void testDefaultlogo() throws Exception {
selenium.open("http://Sitename/samp.aspx");
selenium.type("ctl00_mainContentPlaceHolder_txt_LoginName", "uname");
selenium.type("ctl00_mainContentPlaceHolder_txt_Password", "pwd#12");
selenium.click("ctl00_mainContentPlaceHolder_btn_login");
selenium.waitForPageToLoad("60000");
selenium.click("ctl00_defaultLogo");
selenium.selectWindow("Sample~Window-ID");
verifyEquals("http://Sitename/index.html", selenium.getLocation());
selenium.close();
selenium.selectWindow ("null");
verifyTrue(selenium.isElementPresent("ctl00_defaultLogo"));
I mean by clicking one by one of the follwing commands in Selenium IDE it shows green but if i run the case it failed and shows as i mentioned above
What I can get from your code is that, clicking the "ctl00_defaultLogo" will popup another window. The possible issue could be that after write the command selenium.click("ctl00_defaultLogo") you need to wait for the popup to load.
The possible resolution, insert the command
selenium.WaitForPopUp("Sample~Window-ID", "5000");
before the
selenium.selectWindow("Sample~Window-ID");
This will cause selenium to wait for 5 secs before selecting the popup window.
Hope this helps!!!
some times it may not work for that u better use.
open_window("URL","WindowID or title or name");
selenium.selectWindow("WindowID or title or name");
Related
`I am trying to switch to particular frame using selenium python in loop. It gets executed the first time but after that gives timeout exception error. Here is the code:
Navigate.py:
def navigate_to_frame():
driver.switch_to.default_content()
//Navigation to the frame using execute script
action.py
def perform():
driver.switch_to.default_content()
driver.switch_to.frame(frame)
//Perform required actions
Start.py
for i in range(0,5):
navigate_to_frame()
perform()
The above code works for first time but in the second iteration it throws an exception
I found the solution somewhere else. Came back to answer it.
You are still in the first frame from your first iteration when you try to select from the second iteration.
You need to leave the frame it at the end of the first loop to reset where you are looking at. For example with. a "select frame relative=top".
Following code hangs for about 12 minutes after clicking on "Print Change"
button and then throws error that element not visible at line:
driver.findElement(By.xpath("//button[contains(text(),'Print
Change')]")).click();
System.setProperty("webdriver.chrome.driver",
System.getProperty("user.dir")+ "\\exe\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
driver.get(prop.getProperty("https://genpact-qa-smartit.onbmc.com"));
driver.findElement(By.xpath("//*[#id='okta-signin-
username']")).sendKeys(userid);
driver.findElement(By.xpath("//*[#id='okta-signin-
password']")).sendKeys(pwd);
driver.findElement(By.xpath("//*[#id='okta-signin-submit']")).click();
driver.findElement(By.xpath("//a[#id='header-search_button']")).click();
driver.findElement(By.xpath("//input[#id='globalSearchBox']")).
sendKeys("CRQ000000029504");
Robot robot=new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
driver.findElement(By.xpath("//a[text()='View Full Change']")).click();
Thread.sleep(3000);
driver.findElement(By.xpath("//div[#title='Print']")).click();
Thread.sleep(3000);
driver.findElement(By.xpath("//button[contains(text(),'Print
Change')]")).click();
System.out.println("Clicked on Print Change button");
I am using OS: Windows 10; Browser: Chrome 77.0.3865.90; Selenium: 3.141.59
Any help would be highly appreciated.
Regards,
Surender
First of all for your safety please edit your post removing your username and password that are in your code (and afterwards change them).
As far as your problem is concerned there is a high possibility that:
driver.findElement(By.xpath("//button[contains(text(),'Print
Change')]")).click();
there are more than one elements with the given xpath so the one you want might not be visible.
Therefore you should either be more specific with the:
[contains(text(),' ... ']
or try using the css selectors.
Anyway look up the docs for locating elements and if you still don't find a solution I will be happy to help you again.
Edit: In order to help you I logged in and your solution probably is to replace
driver.findElement(By.xpath("//button[contains(text(),'Print
Change')]")).click();
with
driver.findElement(By.xpath("/html/body/div[4]/div/div/div/div[3]/div/button[1])]")).click();
You specified an implicit wait of 120 seconds , so the code will wait for 120 seconds before throwing in to an exception.
in this case i think the xpath is wrong that's why its waiting for long time (may be there is some extra space in between the text print change). Use any xpath identification tool to check whether the xpath is correct or not
i hope the following code may work
driver.findElement(By.xpath("//button[contains(text(),'Print')]")).click();
I am trying to drag and drop an element over another but I am not able to do so. I am trying to perform the above operation on http://the-internet.herokuapp.com/drag_and_drop
This is my code
we1=driver.findElement(By.xpath("//*[#id='column-a']"));
we2=driver.findElement(By.xpath("//*[#id='column-b']"));
action.clickAndHold(we1);
action.moveToElement(we2, 450, 250);
Thread.sleep(3000);
action.release().build().perform();
Instead of action.moveToElement(we2,450,250) I have even tried using action.moveToElement(we2) and action.moveByOffset(450,250).
I even tried to perform this operation using Robot class.
robot.mouseMove(230, 170);
Thread.sleep(3000);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseMove(450, 200);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
Nothing happens in any of the above code. No error or exception is thrown and Code execution gets completed successfully.
After a lot of effort (hit & try :) ) I was able to find a solution for my problem. It is working fine for the site I mentioned as well as for other sites also where drag and drop functionality is present. Here is the solution:
we1CenterX=we1Points.x+we1Dimensions.width/2;
we1CenterY=we1Points.y+we1Dimensions.height/2;
we2CenterX=we2Points.x+we2Dimensions.width/2;
we2CenterY=we2Points.y+we2Dimensions.height/2;
robot.mouseMove(we1CenterX, we1CenterY);
waitForMe(1); //custom wait
robot.mousePress(InputEvent.BUTTON1_MASK);
waitForMe(1);
robot.mouseMove(we2CenterX, we2CenterY);
waitForMe(1);
robot.mouseMove(we2CenterX+100, we2CenterY-70);
/*Moving the cursor over the element before releasing
the mouse button solved my problem*/
waitForMe(1);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
waitForMe(1);
I have been using Selenium WebDriver. I want to wait until the element is present on the webpage, for which i am using:
WebDriverWait wait = new WebDriverWait(driver, Long.parseLong(timeout));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(locator)));
but my test get stucks in the second line if the element I am looking for, is not present and even beyond the timeout. Pls Help. Thanks.
Maybe:
- the element is present, so no exception is thrown
- then gets stuck because you are not doing anything else afterwards
Try printing smt after the until call. My guess is it will get printed.
Otherwise maybe it's the timeout:
It must be in seconds, not milli seconds.
http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/support/ui/WebDriverWait.html#WebDriverWait(org.openqa.selenium.WebDriver, long)
I got it worked. I changed the timeout from 60000 to 60 since it takes the second argument as seconds and not millisecs.
I need help on wait function in Selenium webdriver.
I have the following code to wait for "Progressing Pop up" to disappear.
It seems it waits only for some seconds and terminates the script. Please let me know what are the other option?
public static void ProcessingData() throws Exception {
WebDriverWait wait1 = new WebDriverWait( driver , 180 );
wait1.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//div[#class='dijitDialogPaneContent']/div/p/b[contains(text()='Processing ...']")));
}
You placed your timeout on 180, which is 180 milliseconds. You probably mean 180 seconds? So use 180000.
I'd take a closer look at your xpath selector... you are providing
...b[contains(text()='Processing ...']
If you know that the text is equal to processing, then you should use
...b[text()='Processing ...'].
If you know that the text CONTAINS Processing ... then you should use,
...b[contains(text(), 'Processing ...']