Not able to switch pop up window having different action points - selenium

I am unable to switch pop-up using selenium on "http://www.azurespeed.com/Azure/UploadLargeFile" after clicking "Start Testing". It is not a frame, alert or window. I want to click on "Choose file" button. I believe it is not a window pop-up as it is present on DOM.

Yes, you are right. It is present in DOM, you can locate the respective element and perform click action.
Code - driver.findElement(By.xpath("//*[#id='file-input']")).click();
After execution of above code window file upload pop up will open.

you need to wait until upload popup appear then for file input use send_keys() to set the value
driver.find_element_by_css_selector('a[data-target="#upload-modal"]').click()
# wait until upload dialog appear
file_input = WebDriverWait(driver, 5).until(
lambda d: d.find_element_by_id('upload-modal').is_displayed()
)
file_input = driver.find_element_by_css_selector('#file-input')
file_input.send_keys('/path/to/file.ext')

Related

How to save a PDF opened in IE new browser

I have a scenario to save a PDF which is opened in a window. By default selenium control moves to the Window, As it is a banking application I cannot repost the URL to save the pdf, I cannot press CTRL + S and right click doesn’t have any required data but using Robot I can click or move to an element, now the save button will enable only if you mouse over at the bottom of the page. I tried using ROBOT mouse over but the pop up did not popped up may be the reason it is not navigating via UI.
I have tried Sikuli also as the save pop up only pop up while mouse over that also failed.
We cannot use Actions as it wont support Webdriver driver, I have used Sikuli and ROBOT class mouse over.
The save Pop up opens only when it is mouse over at the bottom of the page, and it is not happening in ROBOT class as it navigates via DOM. please help

How can I reach the elements of the appeared pop-up using selenium?

In the following ecommerce site "https://www.gittigidiyor.com/", I want to click on "giris yap" button using selenium java but the problem is whenever I hover the mouse to profile icon, this pop-up appears and i try to inspect the pop-up to see the element but nothing happened. Could you please help me how can i click the buttons of this pop-up. I tried by switching to alert/frame but it did not workopened login popup in the site
driver.get("https://www.gittigidiyor.com")
driver.findElement(By.cssSelector("[title=\"Giriş Yap\"]")).click()
WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("[data-cy=\"header-login-button\"]"))).click();
To find the element use below technique:
To search xpath of such dynamic elements use DOM break points:
And select break on subtree modification. Now all changes will break and pause the webpage rendering
Click resume execution or press f8 till your span gets displayed

Selenium Upload a file using button type and button tag instead of file

I have a webpage where I click on a button and an open dialog it's opened and I should select the file to upload. After that, a pop up is displayed saying OK or KO.
I'm able to upload files when the there are files types. But in this case, the element where I click it's:
<
button type="button" read-file="_.partial(submitLang, selectedLang)" id="import-lang" class="btn btn-default"><
/button>
For the rest of the application, I use this and it works:
WebElement element = getPage().findElementById(id);
element.sendKeys(absoluteFile);
But for button types and button tag it doesn't work.
How can I do it? The tests are running on a Linux machine
Thanks a lot!
More info!!
Hi all,
The whole process is: (see image at http://imageshack.com/a/img540/6237/JoTQng.png)
Click on Import button
A dialog is opened and I select a .json file and click Open
An alert is displayed saying "Text properties have been updated".
We are using angular for the frontend and all are REST calls.
We don't have any "file=type". All three are buttons. You can found more code at
http://imageshack.com/a/img633/7299/BQhP7o.png
For a file upload with selenium, you need to find an input tag with the type "file".
Have a look at your HTML and search for it.
When you found it, the rest is pretty straightforward:
Let's say this input-element has id="import"
driver.findElement(By.id("import")).sendKeys(absoluteFile);
If you run into problems, please post more of your HTML, then I can have a look at it.
In my case, clicking on the button made an element appear in the HTML code, I assume due to javascript.
I clicked on the element (which both opens a file upload window and adds the to the HTML), and immediately after send the keys to the input element.
This creates the problem of having to close the newly opened file upload window, however this is not a problem when using --headless mode on google chrome.
I do not have a solution to close this window if you are not in headless mode for your chosen browser.

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 :)