How to Click a Link on a IE webpage? - button

I want to open a button named 'Open' in IE window using VBScript. Source code is like this:
<a title="Devtems Life Menu" href="javascript:OpenOryx('cboClone');">Open</a>

Before I start answering the question, I just want to say that I am by no means an expert at VBScript. My knowledge is based off a lot of messing around with it during weekends and a bit of read the documentation. There may be better ways of doing things, but this works for me.
My recommendation is if you have access to the html, add an attribute to your link so it looks something like this:
<a title="Devtems Life Menu" href="javascript:OpenOryx('cboClone');" id="openMenu">Open</a>
Then you can easily reference it in your code. If you can't access the html, then you may have to use a more roundabout way of checking the contents of each link. The actual syntax is described below in a little script I constructed. It firstly loads w3schools.com, then clicks on the references tab. This uses ie.document.getElementById(arg). Notice that the references navigation panel opens. After that it will prompt you to click the ok button to continue. It will then load google.com, and look through all the <a> tags. If it contains Open it clicks on it. You can use the same syntax, except different details for your script.
' Create the ie object
set ie = createobject("internetexplorer.application")
' Navigate to wherever you want
ie.navigate("http://www.w3schools.com/")
ie.Visible = true
' Call the subroutine we define below
waitForPage(ie)
' Get link by id
' This is a one liner, and I personally think is better than the method below
' first of all you get the tag you want by id
' then you click it
ie.document.getElementById("navbtn_references").click()
' call ie.document.parentWindow.execScript("w3_open_nav('references')", "JavaScript")
' could also be written as:
'set buttonElement = ie.document.getElementById("navbtn_references")
'buttonElement.click()
MsgBox("Click ok to continue to google.")
' Load google
ie.navigate("https://google.com/")
' And wait for it to load
waitForPage(ie)
' Click on a link by attribute (same technique can be used for name etc)
' Get all elements with tag input
set linkElements = ie.document.getElementsByTagName("a")
' Then loop through them
for each possibleElement in linkElements
' If it has a certain name..
if possibleElement.innerHtml = "About" then ' You could use If possibleElement.getAttribute("name") = "foo" Then or possibleElement.getAttribute("class") = "bar"
' Click it!
possibleElement.click()
end if
next
' Subroutine to wait for internet explorer to load a page
sub waitForPage(ie)
do
WScript.Sleep(100)
loop while ie.ReadyState < 4
end sub
Another method is rather than actually finding and clicking on the link, you simply run the script that is run when a user normally clicks on a link. In your case, it could mean running javascript:OpenOryx('cboClone'); directly. Here is how to run javascript code in VBScrpt:
call ie.document.parentWindow.execScript("javascript:OpenOryx('cboClone');", "JavaScript")
I hope that at least one of these methods helps you in writing your script.

Related

Restoring MS Project Views

I'm running a user defined script that changes the view during the course of its computations. When I launch the VBA script, the view is in no particular filter, table or view name. I want to restore the view just as it was before the user launched the script including which task has the focus. It seems like naming the view as the first step when the script launches and saving the task which has focus then activating the view and focus at the completion of the script is a potential way to do this but I'm not having any success. I would delete the named view at the end of running the script. Any suggestions or point me to previous discussions on this forum that may have answered; my search didn't reveal any.
Rod Gill suggested the following but unless I'm doing something wrong it doesn't appear to work.
Dim OrgnlID As Long
Dim OrgnlView As String
Dim OrgnlTable As String
Dim OrgnlFilter As String
OrgnlView = ActiveProject.CurrentView
OrgnlTable = ActiveProject.CurrentTable
OrgnlFilter = ActiveProject.CurrentFilter
OrgnlID = ActiveCell.Issue
' place your code here that does the view manipulations
' followed by the lines below to restore the view before manipulations
ViewApply OrgnlView
TableApply OrgnlTable
FilterApply OrgnlFilter
EditGoTo ID:=OrgnlID

Maxscript, backburner rendering renderElements

I have made a script that takes files from directory, and sends them to backburner for network rendering. When I run the script it renders fine but without the render elements they dont show in the backburner monitor nor do they save.
If I open some of the files manualy and send them to render with backburner it works fine, but not with the script?
The render element is VrayAlpha, but I dont think it matters.
This is the code Im using
on btnRender pressed do
(
outputFilesDir = textModelsOut.text + "*.max"
toRender = getFiles outputFilesDir
man = NetRender.GetManager()
man.connect #automatic "255.255.255.0"
man.GetControl()
for s in toRender do
(
renderModelPath = getFilenamePath s + filenameFromPath s
job = man.newJob file:renderModelPath
job.Submit()
)
man.Disconnect()
)
And this is quote from maxscript documentation, it says that render element data will not be available but it will be processed.
Jobs can not have maps included, and render element data will not be
available for submitted job but render elements will process
correctly. These problems are resent when submitting a job from a
file, but not when submitting the current scene.
Anyways my solution was to use job.newJob() to open each scene and submit the current scene.
You should always include your code (or at least some of it) so that we can check it for issues and test it our selves.
However, I usually use a struct called NetRenderAutomation, developed by Gravey.
You can find it here:
http://forums.cgsociety.org/showthread.php?f=98&t=1059510&page=1&pp=15
I haven't had any problems with it, and it is fairly easy to use, and you are even allowed to modify it, if you need some special features for your self.
Hope you can use the answer.
Else feel free to post some code, and I'll look into it.

Qt, use of "&" in tr

I'm going through the Qt5 Application tutorial. In the creation of actions, I keep seeing the usage of "&" like the follwoing:
newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this)
...
openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
...
enter code exitAct = new QAction(tr("E&xit"), this);
...
I can't seem to find why these "&" are used, the Qt documentations on tr uses these notations without explaining what they are for. Further, when I deleted the "&" symbol, the resulting application doesn't seem to change at all.
As far as tr is concerned & is just another character in the string and has no special meaning.
However it does have a special meaning to QAction: It sets the following character as the entry's shortcut within a menu, so when you have the "File" menu open, pressing the n key will activate the "New" entry, x will active "Exit" and so on. Depending on the OS, the character after the & may also be underlined (on Windows it's only underlined when you press the Alt key).
& is used to indicate a character that should be used for the Alt-key shortcut for a given menu item. Assuming these actions are being put into a menu named &File, pressing Alt-F, then N would activate the New action.
It's for shortcut (in many cases it's Alt and the character).
If you code doesn't have & it will be like this:
now if you have & before the key you want to use for shortcut, it will look like this:
Here I assume you already have these actions added to a menu as in the pictures above, and you also have & for the menu name, something like this:
fileMenu = menuBar()->addMenu("&File");

How to type text on text fields and click on a button using AutoIt

I have a JNLP file (say Test.jnlp). I have opened that file using AutoIt. My code for opening Test.jnlp file:
$d = "D:\Ripon\"
$f = "Test.jnlp"
Run("cmd /c " & " """ & $d & $f & """ ", "", #SW_HIDE)
After opening .jnlp file a Login screen comes. My requirement is to type Username and Password -> Click Login button.
As I couldn't find the identity of elements (text fields, button) I failed to do that. Please help me.
There are a few types of GUI that don't give you ids for controls, almost all Java toolkits are an example of that.
There are several methods of automating them still:
Assuming the window is always the same size (which is often a pretty safe assumption to make) then AutoIt will allow you to click the window at a given position, or send text just to that window. For example in the above case you could try the following code:
ControlSend("Window Title", "", "", "MyUsername{TAB}MyPassword{ENTER}")
Another solution is using accessibility features. If you google 'autoit java accessibility bridge' I'm sure you'll get some results like this one. I've never tried this personally.
There is also a java access bridge no idea how this works either, but other people have been using it for a while.
As a last resort, you have to mimic user mouse and keyboard actions. This really isn't the best solution but at least you can be very sure it will work.
The following snippet of code should work:
Send("username")
Send("{TAB}")
Send("password")
Send("{ENTER}")

CMS links on frontend not converting ie href=[sitetree_link_id=xx]

An issue has been noticed on one of our old sites running 2.4 where when the user creates a link in the CMS content, selecting an existing page to link to, the link is not being converted to the actual URL on the front end and all links are coming through in the format of <a href="[sitetree_link_id=12]">
What would be causing this and how do I fix it?
The tag looks like it's being set incorrectly. It should be [sitetree_link id=12], not [sitetree_link_id=12].
We later added support to the parser for [sitetree_link,id=12] so that links didn't need to contain spaces, but I can't recall if that's in 2.4 or only 3.0+.
Can you confirm that your WYSIWYG insertion is putting in that errant _? If so, you might want to checkout the handleaction_insert function in tiny_mce_imporvements.js to confirm that it has a line like so:
case 'internal':
href = '[sitetree_link id=' + this.elements.internal.value + ']';
If the inserted links don't actually have the errant _ but they aren't being parsed, then try checking your sapphire/_config.php file for this:
ShortcodeParser::get('default')->register('sitetree_link', array('SiteTree', 'link_shortcode_handler'));
If your site makes changes to the ShortcodeParser at all you might have inadvertently turned off sitetree_link support.
If all of that looks in order, perhaps the ShortcodeParser isn't being called for some reason. In HTMLText::forTemplate(), put a debug statement (I like die("I got here!");) to confirm that HTMLText::forTemplate() is actually getting called. If it's not, you might need to manually call it in some pre-processing of your Content variable. Instead of this:
$content = $this->Content;
Do this:
$content = $this->obj('Content')->forTemplate();
I hope that one of those answers help. Either way, it would be great if you could post back, so we could isolate what caused this. It might help us make the API easier to use in SilverStripe 3.1.

Resources