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

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:

Related

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

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

Unable to fetch URL of window containing an alert box while using selenium webdriver

I am using selenium webdriver + java + eclipse + testng for my automation scripts.
I am trying to get the URL of window which contains an alert box.
On clicking download button on a webpage, it opens an alert box in a new window. I want to fetch the URL of this window.
I tried getCurrentURL command for this but i am getting UnhandledAlertException : Modal dialog present. If i dismiss the alert box the window containing is immediately closed so it is not possible to get the URL.
It seems the alert box (modal dialog here) is blocking webdriver in reading the URL of the window.
Please suggest me a solution for this.
Thanks
I'm not sure I understand the question as an alert box does not have any URL !
Anyhow, you can access it this way : Alert alert = webDriver.switchTo().alert();
You can then retrive the text content or interact with it as described in here : http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/Alert.html
I think you need to get the set of windowHandles first for this driver.getWindowHandles();. Then get the required Handle of the newly opened window by iterating them. After that you can switch to the opened window using driver.switchTo().window("pass the handle here");
Now your control comes to new window. Then use like driver.getCurrentUrl();
Hope this could help you. Best Regards :)

Selenium - how to switch to a different (login) window that is brought up?

My application has an admin account and the testing has been within that.
This account then has hyperlinks for 'regular' users that they use for their login, for example:
One http://dmplanning-stage.herokuapp.com/p/7Fimn1FRs1WZe5xmFTUA
Two http://dmplanning-stage.herokuapp.com/p/FRs1WZe7Fimn15TUAxmF
Three http://dmplanning-stage.herokuapp.com/p/mFTUA7Fimn1FRs1WZe5x
These links are generated each time I run the test suite and the id's are different.
I've created a test to locate and click on the hyperlink on a page that lists these users and their login hyperlinks. The test runs and selenium makes the browser bring up the new window but how do I then switch to it, so I can login and continue?
To make it more challenging the other window has an empty title, i.e.
I can get the programmer to add a title but it would take time. Is there any way with/without that to identify and switch to the other window?
I'm assuming you are using Selenium IDE. So from the Selenium Reference
selectPopUp ( windowID )
Simplifies the process of selecting a popup
window (and does not offer functionality beyond what selectWindow()
already provides).
If windowID is either not specified, or specified
as "null", the first non-top window is selected. The top window is the
one that would be selected by selectWindow() without providing a
windowID . This should not be used when more than one popup window is
in play.
Otherwise, the window will be looked up considering windowID
as the following in order: 1) the "name" of the window, as specified
to window.open(); 2) a javascript variable which is a reference to a
window; and 3) the title of the window. This is the same ordered
lookup performed by selectWindow .
selectWindow ( windowID )
Selects a popup window using a window
locator; once a popup window has been selected, all commands go to
that window. To select the main window again, use null as the target.
Window locators provide different ways of specifying the window
object: by title, by internal JavaScript "name," or by JavaScript
variable.
title=My Special Window: Finds the window using the text that appears
in the title bar. Be careful; two windows can share the same title. If
that happens, this locator will just pick one.
name=myWindow: Finds
the window using its internal JavaScript "name" property. This is the
second parameter "windowName" passed to the JavaScript method
window.open(url, windowName, windowFeatures, replaceFlag) (which
Selenium intercepts).
var=variableName: Some pop-up windows are
unnamed (anonymous), but are associated with a JavaScript variable
name in the current application window, e.g. "window.foo =
window.open(url);". In those cases, you can open the window using
"var=foo".
selectWindow would be ideal if you can retrieve the name of the new window that is opened.
If you're having trouble figuring out the name of a window that you
want to manipulate, look at the Selenium log messages which identify
the names of windows created via window.open (and therefore
intercepted by Selenium). You will see messages like the following for
each window as it is opened:
debug: window.open call intercepted; window ID (which you can use with
selectWindow()) is "myNewWindow"
In some cases, Selenium will be unable to intercept a call to
window.open (if the call occurs during or before the "onLoad" event,
for example). (This is bug SEL-339.) In those cases, you can force
Selenium to notice the open window's name by using the Selenium
openWindow command, using an empty (blank) url, like this:
openWindow("", "myFunnyWindow").
You can use the windowhandle to switch to the new window.
Something sort of..
Webdriver driver = new FirefoxDriver();
driver.get // Go to ur login page
driver.click //Click on link which launches new window
Set<String> s = driver.getwindowhandles() //this will return all open windows
driver.switchTo.window(s[1]); //will switch to second window
Hope it helps..

Selenium popup support

Please give me an example java code to open a popup and move RC control to popup.
is there any way to come back on main window after checking some element on popup window.
I have few questions on this as selenium always need windowid to get control over popup.
1-What is the best way to get the windowid of any popup.
2-Should i have to search it in view sources of base page.
3-is it necessary that we must get the windowid of the each & every popup in the view source of the page. if not so what will be work-around.
4-Is window id present in any java-script function? if so ,there is one example
I didn’t get Window id of popup
script language="javascript"
begin
function popup(){
window.open('URL/to/popup.html','PopupName','toolbar=0,location=0,
status=0,menubar=0,scrollbars=0,resizable=0,width=345,height=400');
}
// end
/script
This will definitely help you. Handling Popups
Hope this helps