Accept a Popup using Phantomjs with Selenium - python-2.7

I am using python 2.7, Selenium, and PhantomJs.
When I click the sign in button in my script it goes to a new page and a popup appears that I must accept.
Here is the code I am trying to use. I got it from here
How can I handle an alert with GhostDriver via Python?
sign_in.click()
js = 'window.alert = function(message) { lastAlert = message; }'
driver.execute_script("%s" % js)
driver.execute_script("return lastAlert")
Here is the error that I get:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message:
{"errorMessage":"Can't find variable: lastAlert","request":{"hea
ders":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"95","Content-Type
":"application/json;charset=UTF-8","Host":"127.0.0.1:56712","User-Agent":"Python-urllib/2.7"},"httpVersion":"1.1","metho
d":"POST","post":"{\"sessionId\":
\"3832e2c0-4902-11e6-b766-0d7f487d0794\", \"args\": [], \"script\":
\"return lastAlert
\"}","url":"/execute","urlParsed":{"anchor":"","query":"","file":"execute","directory":"/","path":"/execute","relative":
"/execute","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/execute","q
ueryKey":{},"chunks":["execute"]},"urlOriginal":"/session/3832e2c0-4902-11e6-b766-0d7f487d0794/execute"}}
Screenshot: available via screen
I am not very experienced with javascript and a point in the right direction would be useful.

Here is the Behat step that I'm using:
/**
* This step overrides windows.confirm and basically accepts it before it is displayed.
*
* #When /^(?:|I )bypass the popup$/
*/
public function bypassPopup() {
$function = "
var realConfirm=window.confirm;
window.confirm=function(){
window.confirm=realConfirm;
return true;
};
";
$session = $this->getSession();
$session->executeScript($function);
}
You place it before you click on the button and when you click your popup will be accepted automatically.
In this case, only the first popup will be accepted.

Related

Attachments moved away from Item after validation and before submit process in Apex

I have multiple File Browser Item fields on one page of Application in Oracle Apex.
What happens: When I miss any Item for which validation error fires, I want to hold that file to the browser but I usually loose it if I get that validation error. Is there a solution for the same like other Items fields hold previous value except File Browser Item field. Please see below ss:
Anshul,
APEX 4.2 is very old and no longer supported. A later (or preferably latest) version of APEX will behave differently as Dan explained above.
Can you import your application into apex.oracle.com (which is running APEX 20.1) and you will probably see better results. Based on this you can hopefully use it as justification to upgrade your environment.
Regards,
David
Go to your page-level attributes and a function like the following in the Function and Global Variable Declaration:
function validateItems(request) {
var $file1 = $('#P68_FILE_1');
var $file2 = $('#P68_FILE_2');
var errorsFound = false;
if ($file1.val() === '') {
errorsFound = true;
// Show item in error state
}
if ($file2.val() === '') {
errorsFound = true;
// Show item in error state
}
if (!errorsFound) {
// I think doSubmit was the name of the function back then. If not, try apex.submit
doSubmit(request);
} else {
// Show error message at top of page, I'll use a generic alert for now
alert('You must select a file for each file selector.');
}
}
Then, right-click the Create button and select Create a Dynamic Action. Set the name of the Dynamic Action to Create button clicked.
For the Action, set Type to Execute JavaScript Code. Enter the following JS in code:
validateItems('CREATE');
Finally, ensure that Fire on Initialization is disabled.
Repeat the process for the Save button, but change the request value passed to validateItems to SAVE.

Unchecking checkbox in oracle apex

Created an report with checkbox using apex_item and when checked more than one check box i will display alert message "not to check more than one checkbox with ok button " after clicking ok it should be unchecked . please find my JavaScript code that displays alert message
if($("input[type=checkbox]:checked").length > 1)
{
var msg = alert('You are not allowed to select more than one employee');
}
It's best to use the APEX JavaScript APIs for this type of thing. You can find them here: https://apex.oracle.com/jsapi
If you're getting started with JavaScript and APEX, you may find these slides useful: https://www.slideshare.net/DanielMcGhan/getting-started-with-javascript-for-apex-developers
Here's a solution that should work for you (just change the name of the item to match yours):
var cbItem = apex.item('P1_CHECKBOX');
if (cbItem.getValue().length > 1) {
alert('You are not allowed to select more than one employee');
cbItem.setValue(); // Passing nothing to clear the value
}

button always return the last ID, not the correct one

I'm creating a menu in gaffer that populate automatically from a string list called "shotlist"
the idea is to have a custom menu for each entry of the list and have an action relative to each entry too, like :
click on sh001 = sh001
click on sh002 = sh002
click on sh003 = sh003
my problem is that my code return :
click on sh001 = sh003
click on sh002 = sh003
click on sh003 = sh003
I understand that when I click on a button, it always return the 3rd value of "shotlist", as it's the last one than the loop worked on, but I dont understand how to set the loop differently to have the right result
actually my code is :
def shotSelection( menu ):
shotVar=str(shotName)
print shotName
scriptWindow = menu.ancestor( GafferUI.ScriptWindow )
root = scriptWindow.scriptNode()
root["variables"]["projectshot"]["value"].setValue( shotVar )
root=application.root()
shotlist=["sh001","sh002","sh003"]
for shotName in shotlist:
GafferUI.ScriptWindow.menuDefinition(application).append("/Pipeline/ShotSwitcher/{0}".format(shotName), { "command" : shotSelection } )
I have also tried with the method described here but i dont understand well enough how it's work to apply it to my script.
the menu creation part from gaffer works well. but I dont found a way to set up my menu from the list and have the right action on it at the same time
thank you
EDIT:
actually I found the problem but not sure how to fix it
GafferUI.ScriptWindow.menuDefinition(application).append("/Pipeline/ShotSwitcher/{0}".format(shotName), { "command" : shotSelection }
shotSelection does not transmit any info of the shot clicked on
i fixed my issue with functools(), allowing to transmit the value in each loop

ember delete record, not able to delete after first attempt

I have a workflow in which I have to delete a record, but in case back-end throws any error then I show an error dialog with a close button on it. The user can close that error dialog and go back to the main screen where he can again submit the action for deleting the record. But I am getting the following error when I try to click on delete for the second time:
Attempted to handle event deleteRecord while in state root.deleted.inFlight
Can someone guide me what can be the potential issue?
My code for reference:
File: component.js
let person = this.get('person') -> this is the model
person.destroyRecord().then(() => {
// if success, show success message
this.showSuccessModel();
}, (error) => {
// show error message in a dialog, with close button
this.showErrorModel();
});
When user clicks on close button, and when he click on delete action again, then I am getting the error above.
I was able to fix the issue, in case of errors, I was using rollBackAttributes() function on the model object as suggested by ember documentation but just realized I also have to do:
model.send('becameInvalid'), as otherwise just rolling back Attributes does not work. So, my working code will look something like this:
let person = this.get('person') -> this is the model
person.destroyRecord().then(() => {
// if success, show success message
this.showSuccessModel();
}, (error) => {
// show error message in a dialog, with close button
if(person.get('hasDirtyAttributes') {
person.send('becameInvalid');
person.rollBackAttributes();
}
this.showErrorModel();
});

Sikuli api - "OK" click ignored during file upload

Using:
Sikuli-api stand alone jar
python 2.7.6 with pyjnius
Ubuntu 14.04 Trusty
Issue:
The Sikuli DesktopMouse click() method works in almost all situations except when I'm trying to click "Open" on a file upload [Ubuntu Open](http://i.stack.imgur.com/nZsvv.png) from the upload dialog or "Allow" on the Flash Player Settings dialog [Flash Player Settings](http://i.stack.imgur.com/7OrbG.png). If I navigate to these areas manually I can click on these buttons without error. I have to imagine that it is some sort of permissions issue (because all other clicks work including all the clicks in the code snippet below. I mean, the exception at the bottom is thrown, meaning that the "Open" button is both seen and clicked on, twice), but I haven't the foggiest what that would entail. There are no errors to share because the click doesn't technically fail
About Code:
self.get_target() returns an ImageTarget
self.mouse and self.kb are instances of DesktopMouse and DesktopKeyboard respectively.
self.box creates a DesktopCanvas and draws a box around the target DesktopScreenRegion
Code:
def upload_file(self, path, title):
screen = sikuli.DesktopScreenRegion()
locationTarget = self.get_target("images/ubuntu_location_field.png")
locationTarget.setMinScore(.6)
locationField = screen.wait(locationTarget, 5000)
if locationField is None:
editTarget = self.get_target("images/ubuntu_location_edit.png")
edit = screen.wait(editTarget, 5000)
if edit is None:
searchTarget = self.get_target("images/ubuntu_upload_search.png")
search = screen.wait(searchTarget, 5000)
self.box(search)
self.mouse.click(search.getCenter())
else:
self.box(edit)
self.mouse.click(edit.getCenter())
locationField = screen.wait(locationTarget, 5000)
self.mouse.click(locationField.getCenter())
self.kb.type(path + "/" + title)
okTarget = self.get_target("images/ubuntu_upload_opensave.png")
ok = screen.find(okTarget)
self.mouse.click(ok.getCenter())
if screen.find(okTarget):
self.mouse.click(ok.getCenter())
if screen.find(okTarget):
#GETTING TO THIS POINT MEANS THAT THE BUTTON CAN BE SEEN AND CLICKED
#BUT THAT THE CLICK IS NOT DOING ANYTHING
raise Exception("Upload file is acting like a bitch.")
sikuli.API.pause(10000)
Found that the issue stemmed from using the firefox webdriver, which apparently has much higher security than its chrome counterpart. All operations can be done on chromedriver.