I have this script here which is loading a profile on an unfocused safari tab and saving the text I want in a variable
tell application "Safari" to set the URL of tab 2 of window 1 to "https://URLproduct/" & serialNumber & "/definition"
delay 2.5
However some of the data is only available after a click on a button (this is a pop-up like overlay with a button, which make the another text not accessible until you press on "OK", also this button is not always here)
button HTML is :
<button class="btn btn-primary" autofocus="" ng-click="ok()" tabindex="0">OK</button>
which I press with this script :
do JavaScript "document.getElementsByClassName('btn btn-primary')[1].click();" in tab 2 of window 1
Weirdly sometime is working sometime not and I can't add too much delay
Can I add a script which would wait for this button ('btn btn-primary') been availible (fully loaded) and then try again to get the text by with my 1st script?
--
May be I can add something like
tell application "Safari"
tell document 1
repeat until ("btn btn-primary" is in its source)
delay 0.5
end repeat
end tell
end tell
then the click script?
yes, you can start executing your script after the page has loaded. This makes sure that the button is clickable (in case it appears at all).
Put this code in to your script:
tell application "Safari"
repeat until (do JavaScript "document.readyState" in document 1) is "complete"
end repeat
end tell
Happy scripting!
Related
Attempting to create automation to open a Safari browser with multiple tabs and login to common websites I use each day. I've achieved opening the browser and adding new tabs with specific URL's and prompting user for username and password but am having difficulty with simply moving between the open tabs.
I have tried assigning an index, naming the "current tab", using a title, etc. nothing seems to work... see sample below...
--Prompt user for login information
set GEmail to text returned of (display dialog "Enter Password" with title "Gmail" default answer "")
set GPassword to text returned of (display dialog "Enter Password" with title "Gmail" default answer "")
--Activate Safari and open new tab with URL
tell application "Safari"
activate
make new document with properties {URL:"https://gmail.com"}
delay 3
tell application "System Events"
delay 2
keystroke tab
keystroke GEmail
delay 2
keystroke tab
keystroke GPassword
keystroke return
end tell
--Create new tab pointing to Google > this does not actually open the new tab
set the URL of (make new tab in window 1) to "http://www.google.com"
end tell
I’ve tried multiple things but still cannot seem to actually move between the tabs and will eventually need to add several more tabs which I will need to toggle between.
To create a new tab, while setting focus to it, at a given URL use, e.g.:
tell application "Safari" to ¬
tell front window to ¬
set current tab to ¬
(make new tab with properties {URL:"http://www.google.com"})
I am using the below code for this, this is present inside a frame and this also clicks the button but after button is clicked the control is lost. The possible reason i see is the page lands on same page which extra options after the "Submit An App" button is clicked.
I am using c# to code it. The first line finds the button the second line clicks but go for a timeout. I have seen this behavior fist time not sure how to work it out.
IWebElement field = VelocityDriver.FindElement(By.Id("AppSub"));
SeleniumExtensions.ClickElementAndContinue(field);
I am trying to automate a web based application and I am having trouble finding buttons in order to click on them.
Basically there are a number of text boxes on a screen and next to each text box is a "Go" button. Once you hit the "Go" a popup will be overlayed on the screen saying "Are you Sure?" and 2 buttons Yes/No. Where I am getting stuck is after the first set of buttons on the Yes/No popup buttons. Each button has a non-unique class name and no name variable, so I am finding each button by its tagName and then clicking on the relevant element
WebElement aButtons = driver.findElements(By.tagName("button");
aButtons .get(x).click();
This works until aButtons .get(x).click(); throws an exception saying the element isn't clickable. On further inspection of aButtons it has a size of 78 elements, despite there being only 33 visable buttons on the page.
Does anyone have a suggestion on how to find my buttons better? Or perhaps how to handle the exception such that I can, with a bit of trial and error, find the element? If the exception could be ignored, I could probably use a for loop in increments of 10 in order to find which element the Yes/No buttons correspond to.
If I ruled the world I would go to the developer of this webpage and ask them to make the buttons more easily identifiable, but that unfortunately is out of the question
When I inspect the elements in question this is the block in the html that gets highlighted
"Go" button:
<
button type "submit" ng-click="vm.click()" ng-disabled = "vm.isDisabled()"
class = "btn btn"> Generate <button/
>
<
button class ="btn" ng-show="vm.runScripts" ng-click="vm.runScript()" ng-
disabled ="vm.runScript.isScriptRunning">
>span class = "glyphicon play" aria-hidden="true"></span>
Yes
</button>
I was having trouble with the formatting of the above since I am unfamiliar with posting html code.v the 2nd button is the yes button.
(Note the "No" button has the same "btn" class name). When I tried to find the element based off of the class name " glyphicon play" I got an error saying compound class names are not valid. I was able to find the "Go" buttons since they were sequential, so like aButtons .get(1).click(); was the first Go button on the page, aButtons .get(2).click(); was the second etc.
I cannot share the url since it is an internal site.
I am using the recorder of the testComplete Software
I would like to adjust the result for doing for making an end to end website test.
But before that I have an issue when I try to replay the record result: I have a dropdown list that takes few seconds before be displayed.
On picture it is the Droipdown list where the item 'Admin' has to be selected
I saw ther is a Delay method in tools, and it woeks is i put this action but I don't see a WaitFor method like I saw in Testcafé or Ranorex
Please Do you know how to do it and could you help me?
I found : you have to copy paste the action with the element you want to wait.
Move the new action before the click action and choose visibleOnScreen
I am trying to trap mouse click events in Safari with Applescript. My Applescript does what it needs to do, but I want to terminate if the user clicks on the document in Safari. I would like to set up an On_Click event in Applescript that would fire if the user clicks in the Safari document.
I do not know how to "trap" a mouse event with applescript. You'd have to use objective-c and the cocoa APIs for that.
However you might do it another way. Here's a quick example. Save this as a stay-open applescript application. When you run it the Safari window will scroll. To pause the scrolling just click the dock icon of the applescript. If you click the dock icon again then the scrolling will start again and vice versa. You'll notice that every time you click the dock icon the "on reopen" handler is executed which toggles the shouldScroll variable between true and false.
Anyway, I hope this gives you an idea for making your own script work. Remember you can quit the stay-open applescript by right-clicking on its dock icon and choosing quit. Good luck.
property shouldScroll : missing value
property theCounter : missing value
property counterMaxValue : missing value
on run
tell application "Safari" to activate
set shouldScroll to true
set theCounter to 0
set counterMaxValue to 2000
end run
on reopen
tell application "Safari" to activate
set shouldScroll to not shouldScroll
end reopen
on idle
if shouldScroll then
if theCounter is greater than counterMaxValue then set theCounter to 0
tell application "Safari" to tell document 1
do JavaScript "window.scroll (0," & (theCounter as text) & ")"
end tell
set theCounter to theCounter + 20
end if
return 0.1
end idle
You might exit the script when the focused window becomes a normal browser window, by for example testing if the frontmost window has a full screen button:
tell application "System Events" to tell process "Safari"
repeat until exists value of attribute "AXFullScreenButton" of window 1
--do something
delay 1
end repeat
end tell
Or if the script is supposed to stop when Safari becomes the frontmost application:
repeat until frontmost of application "Safari"
--do something
delay 1
end repeat