Python Selenium Webdriver: How to handle Alert Windows - python-2.7

I've webpage wherein I select 'Disable' radio button and click 'Apply/Save' button to apply settings. But unfortunately an Alert window pops saying 'If disabled, the information captured by the Broadband Router will be lost. If you wish to save the current log information, click the "Cancel" button, view the current system log, and use the Save option from the File menu to save the log data.'
How do I click 'ok' button to accept the applied settings?
Please below the screenshot for reference.
Please find below my python code:
Note: My alert.accept() function is not clicking the 'ok' button to apply settings
from selenium import webdriver
driver = webdriver.Firefox()
driver.find_element_by_xpath('/html/body/blockquote/form/table[1]/tbody/tr/td[2]/input').click()
try:
driver.find_element_by_xpath('/html/body/blockquote/form/p/input').click()
alert = driver.switch_to.alert()
alert.accept()
except:
print 'Not disabled'

I'm new to automation. If the focus is on OK button, you could try
SendKeys.SendWait(#"{ENTER}");
This worked for me in c#.

Try alert command with some wait or sleep to appear. If it is not working you may try with simulating keys. JavascriptExecutor work very well here.
In Java
JavascriptExecutor js=(JavascriptExecutor)driver;
js.executeScript("call function to accept");
Thanks

I realize this is an old post, but for future reference, I will try to answer the question.
alert = driver.switch_to.alert()
The above code is incorrect. alert is not a function call, but a variable.
alert = driver.switch_to.alert
Notice how the next code is missing parentheses. This is the correct code.

Related

How can I Close a popup window, after execute Update SQL. (Oracle APEX 21.1)

I created a pop-up page. That pop-up window has a radio button, a text box, and an execute button. I want to work that page working like... when pressing the button, run a update SQL with the values of the radio button and text box, and close itself.
I tried that answer in the following link. But the pop-up page just reloaded and the page stayed open. How to close popup window in Oracle-apex?
If possible, I would like to validate the value of the text box. If it was an incorrect value then break the process with a message. If path that validation, run a update SQL and close the pop-up window.
Thank you for your kindness for read this confusing question.
You should be using a "Close Dialog" process type after your Save Process.
Make sure that you also set the server side condition accordingly so that the dialog only closes after your save process.
I GOT RESOLVED IT!
Not use any close method, redirect util is fine work like this APEX_UTIL.REDIRECT_URL (APEX_PAGE.GET_URL(p_page => 7));
Thank you to all ppl for look this page :)

How to close window in apex builder on clicking a button

I have an apex page where I have a button "SAVE & CLOSE" . On click of that button, I first want to save the data and then close the page.
I have a PLSQL code at point "Processing" to save the data.
I have then created a Branch at Point = "After Processing" and Type ="PLSQL Procedure" and written below code to close the window.
Begin
htp.p('<script type="text/javascript" >');
htp.p('window.close();');
htp.p('</script>');
end;
I have added the button's name in server side condition : When button Pressed.
But this doesn't work. When I click on apply, it doesn't close the window. It gives me an error :
"Error: SyntaxError: Unexpected token < in JSON at position 0 "
Can you please help me resolve this error and tell how can I close the window in button click.
Thanks,
Abha
You can use only APEX components and not write a single line of code :)
Set action for your button to "Submit page" - so all items will be submitted to use their values in processing. Image below will help you.
Now, for processing your pl/sql code use process in processing(left side on the picture).
Here you can create a new process and set type to "Close dialog" this process will automatically close the window. Without any javascript etc.. Apex is processing from top to bottom, so if you make this process last, it will always close the window after all processes are done.
You can as well set process server side condition, so it will not trigger every time.
Be careful with javascript - some web browsers are processing them in different way.
Hope it will help. Have a nice day !
Hi I got it working with other method :
Instead of type : PLSQL Procedure" select Type = "Page or URL Redirect"
and give
javascript:window.close()
in the Target.
This works.
What I did was make the page Modal. Then I added a Button called btnClosePage with a Dynamic Action (True Event) that calls "Close Dialog". I am working in Oracle Apex 20.2.

How to show notification on tizen

i need to show notification on tizen.
i've try the below code.
Tizen::Shell::NotificationManager notiMgr;
notiMgr.Construct();
NotificationRequest request;
request.SetAlertText(L"AlertText");
request.SetTitleText(L"TitleText");
request.SetAppMessage(L"AppMessage");
request.SetNotificationStyle(NOTIFICATION_STYLE_NORMAL);
notiMgr.Notify(request);
i will get notification while put this code into tizen notification example.That means this code works any form in the example.However,in my simple button click i can't.There is no error occur while click the button.But nothing happens.
As the logs say: "The application does not have the privilege to call this method."
If you look up NotificationManager::Notify you'll see that it requires the privilege http://tizen.org/privilege/notification.
To request this priviledge for your app, open your manifest.xml file, click on the Privileges tab, click Add..., enter the string http://tizen.org/privilege/notification, click OK and rebuild/deploy your app.

Access content property in the debugger

how can i access the content property of a controller within the chrome debugger.
I really try to find a way to debug my application. So far i can't find a way to do that.
Thank you
Alex
add the statement
debugger;
in the method you want to debug,
Open Google Chrome, CTRL+SHIFT+i
Hit the URL of your application, navigate to the state where you think the code would run
Google Chrome automatically stops at the debugger; statement and focuses you to the sources/scripts tab as you can see in the picture
Inside the Watch expression tab click on the "+" too evaluate code in your case it would be
this.get("content");
As long as you have this breakpoint you can switch to the console panel and execute the code in that context, whenever you are done you can either close the panel by clicking CTRL+SHIFT+I or the close button down there, you can add breakpoints manually by clicking on the line number as well , Hope this helps
For more info
I'm using Ember Extentions which is not ready yet but certainly usable.
There are 2 possibilities
Use the Ember Inspector Tool for Chrome: It is not officially released yet, but from what i have heard it seems usable. I had no time to try it myself yet, but here is an article telling you how to install and use it.
Get access to your controller in the console of your browser. And then examine it as you like. Here is the code to get access to your controller.I use it myself in my app for debugging:
// i assume that your Ember.Application is stored in the global var App
var App = Ember.Application.create({
getController : function(name){
return this.__container__.lookup("controller:" + name);
}
});
// now you can use it like this. To get the users controller (App.UsersController) just use this in the console:
App.getController("users")

How to open a new tab in same browser using robot frame work

As far as I know there is no straight keyword to open new tab in selenium2library. I have seen the below code which opens a new tab in IE(default browser)for the given URL
webbrowser.open_new_tab(url)
But I want to write a keyword which opens a new tab on current running browser (it may be any browser).
You can try
Execute Javascript window.open('')
Get Window Titles
Select Window title=undefined
Go To ${URL}
This Code helps to Open New tab in the same browser and collect the Windows Title of all tabs in same browser.
Based on the Window Title name , it identifies the Newly opened tab and launch the URL
You can use the Javascript Keyword
Execute Javascript window.open('NewTabUrl');
Example:
Execute Javascript window.open('https://www.google.com');
It's sloppy, but you can try:
from selenium.webdriver.common.keys import Keys
actions.key_down(Keys.CONTROL)
element.send_keys('t')
actions.key_up(Keys.CONTROL)
I'm not aware of a browser-agnostic method.
After opening a new tab you can change tabs by finding the window handle with driver.window_handles and switching to the appropriate handle: browser.switch_to_window(handle)
You can use an AutoIt Library For Simulating KeyStroke in Robot Frame Work
Import AutoItLibrary
Import Selinium2library
send "^t" Open the New Tab
same way simulate others
Ctrl+Tab – Switch to the next tab – in other words, the tab on the right. (Ctrl+Page Up also works, but not in Internet Explorer.)
Ctrl+Shift+Tab – Switch to the previous tab – in other words, the tab on the left. (Ctrl+Page Down also works, but not in Internet Explorer.)
Ctrl+W, Ctrl+F4 – Close the current tab.
Ctrl+Shift+T – Reopen the last closed tab