Selenium Robot Framework Pop Up Access - selenium

I am not able to access a pop up window using selenium webdriver robot framework.
Steps:
site "http://carlightking.com/"
click on "Search By Vehicle" Tab.\
pop up window opens
I tried to access the pop up using "select window" keyword with some locators like id and name but was unsuccessful. It shows
ValueError: Window locator with prefix 'id' is not supported.
How can I select this pop up window and access elements over it?

The Problem is that the popup is inside a iFrame.
<iframe id="popup_selector" src="//carlightking.com/selector/selector-home-popup.php" width="100%"></iframe>
hence you have to explicitly select the iframe first
*** Test Case ***
CarLightKing
Open Browser http://carlightking.com/
Wait Until Page contains Element link=Search by Vehicle 5s
Click Element link=Search by Vehicle
Select Frame id=popup_selector

Related

Selenium didn't click second time after being reloaded to homepage

I have a test case here:
My page left part is an accordion menu. When I performed click parent menu, it worked. And the right part of the website will display "You do not have authority" and return me back to the homepage.
The right part will display normal content when I second visit. So I should click the menu again and I write like so in my test code. But it didn't perform any click action - just passed the click action to the next step. So my test fails and throws error.
I looked at my browser which is controlled by selenium webdriver. It is apparently frozen after the page reloads to the homepage.
The error message shows:
Test method AutomationTesting.cuteTest.CheckChocolate threw exception:
OpenQA.Selenium.WebDriverTimeoutException: Timed out after 5 seconds ---> OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[#class='menuChocolate']/a"}
My test code: (Why I have to click the second time is because this page needs to come the second time to show the normal UI)
DessertsMenu.Click();
WebDriverWait waitForMenu= new WebDriverWait(Driver, TimeSpan.FromSeconds(5));
waitForMenu.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[#class='menuChocolate']/a"))).Click();
DessertsMenu.Click();
WebDriverWait waitAgain= new WebDriverWait(Driver, TimeSpan.FromSeconds(5));
waitAgain.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[#class='menuChocolate']/a"))).Click();
I looked at the browser which is controlled by selenium, it actually clicks the menu. But I don't know why it didn't click again.
Is there anything I am missing?
If the page is reloaded, I think you will have to locate the parent menu again.
If, even after locating the element, you are not able to click the parent menu, then I would suggest you to try clicking the parent menu using JavaScriptExecutor.
https://www.guru99.com/execute-javascript-selenium-webdriver.html
You can troubleshoot it with below options--
can you check after first click if it is showing the same xpath ,it might be possible that after clicking xpath is getting changed
you can put some wait like one second between first and second click
3.If above two options are not working then you can use JavaScriptExeccutor

How to select a popup in an iframe with robot framework / selenium

I want to write a testcase for a webapplication with Robot framework and the selenium library. The situation is that when a button is clicked, a popup page is shown withtin the webpage.
This popup is inside an iframe and has it's own etc.
I have a test that verifies if the popup page is opened by searching for presence element x.
Things I have tried are:
1a. Select frame xpath=xpath iframe
1b. Element text should be xxx
2a. Switch window title=title of popup that can be found within the element.
2b. Element text should be xxx
In both situations the test fails. The popup page is opened but the error messages shown are:
Element with locator 'iframe' not found.
Unable to locate window with title 'xxx'.
I searched for similar problems but didn't find any solutions thats helps my case.
try this
Select Frame css:iframe[id^="PopupBoxIframe_"]
where id=yourid
to get back lateron you use
unselect frame

Robot Test not selecting new window

the application under test is an internal site. i am not able to select the new window when i run the test in IE. this is the part of my test that is having the error
Run report
input text txtSearchKey TestProduct
click element searchButton
click element xpath=//*[#id='tblProductSelect']/tbody/tr[1]/td
wait until element is not visible loadingDiv
click button id=btnRunReport
wait until element is not visible loadingDiv
get window identifiers
get window names
select window Product Report
when btnRunReport is clicked, the application opens in a new tab and shows the report. this is whats happening when a user goes to the application and generates a report in chrome or in IE.
when i run this test, it works fine in Chrome. the report opens in a new tab and i can select that tab. in IE, it opens in new window, which is expected behavior (reference: https://github.com/SeleniumHQ/selenium/issues/5108).
i have no problem with it opening in new window but i am not able to select that new window. im getting this error - ValueError: Unable to locate window with handle or name or title or URL 'Product Report'
the "get window identifiers" and "get window names" only gets 1 browser. it doesnt seem to recognize the second one. also, on the Suite Teardown, the second window doesnt get closed.
thanks. i hope someone can help me.
Here are my system specs:
OS - Windows 7
Browser - IE11
Robot Framework Version - 3.0.2
IEDriverServer version - 3.4
Selenium2Library version - 1.8.0

Selenium Webdriver 2.30 unable to identify object on the standard Salesforce lookup pop-up window

I am using Selenium Webdriver to automate functional TC in Salesforce application.
Test Scenario:
- On a case page, clicking the "Lookup" i.e., search icon opens up standard Salesforce search popup. I need to input specific string to the search field and click "Go" button.
Although I am able to click on the Search button, the script fails to identify any field on the popup.
I used Alert(), getWindowHandle & iterator functions to verify if the driver is working on the popup window. Yes it is.. the popup is is the working window. I could able to confirm this using the Java id for the browser window. But still it fails to identify any fields.
Let me know if any of you faces similar issue and any solution.
Do let me know if you like to have access to my working sandbox. Would be able to manage it.
Thanks, Manju
I believe the problem is that the elements inside the popup window are in a frame. After switching to the new popup window you need to switch to the frame first before being able to access any of those elements using:
WebElement frameLocator = driver.findElement(By.id("searchFrame"));
driver.switchTo.frame(frameLocator);
Further to Bob's answer you'll also then need to switch to the "resultsFrame" in order to use any of the links returned by the search. Note that in order to switch to a sibling frame you must first go up to the parent of the frameset using:
driver.switchTo().defaultContent();
(frameset guidance here: http://darrellgrainger.blogspot.co.uk/2012/04/frames-and-webdriver.html)
With Selenium IDE:
I was able to select the Salesforce PopUP with this code:
Command:selectPopUp
Target:
Value: Your popUp title
And the result frame:
Command:selectFrame
Target: name=resultFrame
Value:

Automating "Browse" button event in Selenium

I need to automate the "Browse" button click from Selenium.
For this, I have tried
driver.findElement(By.xpath("//*[#id=\"dnn_ctr383_View_filename\"]")).click();
and
driver.findElement(By.cssSelector("Css path")).click();
Both gives me org.openqa.selenium.NoSuchElementException: Unable to locate element: exception.
I have seen this link here where the author suggest to use AutoIT, but in step 2, the script, the author has created is for IE. Can someone please suggest, how I can automate the "Browse" button click in firefox?
Any help is much appreciated.
Directly send the file path to the id, like so
driver.findElement(By.id("dnn_ctr383_View_filename")).sendKeys("C:\\path\\to\\file");
The above step is the answer for your first two steps
Click on Browse
Select a file to upload
For the third step(click upload), looking at the screen capture I do not see any button which says "Upload". So just click "Save" and I assume that your file will successfully get uploaded.
There are two things that u need to consider here:
Clicking the browser button: Usually handled by an alert or popup, if the driver is not able to find the element by xpath(which u have acquired from firebug or chrome's inspect element) you should consider looking for iframes in the page source. If an element is in a different frame altogether , u need to switch frames in order to find the element like this
WebElement frame = driver.findElementById("name_of_iframe");
driver.switchTo().frame(fr);
now you can find your element using xpath or css selector like u did. Once completed u can move out of the frame by:- driver.switchTo().defaultContent();
Uploading the file from desktop: Since selenium works only on the html in the browser session u invoked from the driver, it can't perform operations on your desktop.Once you are able to click the browser button u can use Auto it(works only on windows) or Sikuli(works with mac, linux, windows and even android) to simulate your events based on the position of your upload button.
Hope this helps