autoit IE click on a button in a website - autoit

I am trying to open a link by clicking on button inside a website.
This is the element :-
<div class="btn3">Like</div>
I tried this
$oBtn.classname = _IEGetObjById($oIE, "Like")
_IEAction($oBtn, "click")
not working. any help. Please.

You are doing it all wrong.
Try reading the help file.
This will work
Local $oInputs = _IETagNameGetCollection($oIE, "div")
For $oInput In $oInputs
If $oInput.classname == "btn3" Then _IEAction($oInput, "click")
Next

You can use $oBtn.classname only if you create an internet application object or an xml object with autoit. OR if you use _IETagNameGetCollection()
Here is an example:
#include <IE.au3>
Local $oIE = _IE_Example("form")
Local $oInputs = _IETagNameGetCollection($oIE, "input")
Local $oBtn
For $oInput In $oInputs
if $oInput.class = "btn3" Then
$oInput.Click
ExitLoop
Next
_IEQuit($oIE)
Of course you will need a little modification to the code since we know nothing about the website you are trying to automate

Related

Python Selenium Webdriver Wait until Element is Loaded

The idea is to scrape a Website. By doing so, I wanted to scrape it via screenshots and then extract the data off the screenshot. Because in the Data I wanted to scrape is not in the HTML-Code and to be honest I didn't know how to handle it ( I am pretty new to python/programming).
It is working fine so far, but I had the problem that WebDriverWait doesn't work properly.
That's the Webpage: https://exporo.de/investment/betreutes-wohnen-huerth and in detail it's this dynamic part:
<div class="key">Bereits investiert</div>
<div class="value"
ng-controller="pubSubController as pubSubCtrl"
ng-show="pubSubCtrl.hasProject(2385)"
ng-bind="pubSubCtrl.getProject(2385, 'total')"></div>
So this is my code so far(the loop of it):
while AktuellerWert1 < Endwert1:
Zeit = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
driver1.get_screenshot_as_file(png_link % FileName1)
img = Image.open(png_link % FileName1)
PNG1 = image_to_string(img)
PNG1_bearb = PNG1.split()
AktuellerWert1 = PNG1_bearb[PNG1_bearb.index('investiert') + 1]
Endwert1 = PNG1_bearb[PNG1_bearb.index('Finanzierungsziel') + 1]
if AnfangsWert1 != AktuellerWert1:
with open("/Users/davidoverbeck/Dropbox/Screen/Exporo/%s.csv" % FileName1, 'a') as csvFile:
writer = csv.writer(csvFile)
writer.writerow([AktuellerWert1, Zeit])
print(AktuellerWert1)
else:
pass
AnfangsWert1 = AktuellerWert1
driver1.refresh()
element = WebDriverWait(driver1, 2).until(EC.visibility_of_all_elements_located((By.XPATH, '/html/body/main/section[1]/section/div[2]/div[2]/div[1]/div[2]/div[10]/div[2]')))
else:
with open("/Users/davidoverbeck/Dropbox/Screen/Abgeschlossen.csv", 'a') as csvFile:
writer = csv.writer(csvFile)
writer.writerow([Zeit, FileName1])
print(FileName1, 'abgeschlossen')
driver1.close()
It's working fine for 2 minutes and then it gives me the following error:
selenium.common.exceptions.TimeoutException: Message:
(no message behind it?!)
I am not sure whether the loop does anything at all or, in case it's working, what's wrong with it?
Thank you for your help!
I'm under the impression that the data you're looking for is here:
https://exporo.de/pubsub/initial .
In that case no need to parse html, you will need to parse the json.
See F12 -> network tab -> Type column = json

Autoit - searching for a URL in a web page and click on it

I'm trying to figure out how can I click a URL that matches a specific pattern.
For example:
#include <IE.au3>
#include <MsgBoxConstants.au3>
local $pattern = "/123/"
Local $oIE = _IECreate("www.example.com",0,1,1,1)
Local $oLinks = _IELinkGetCollection($oIE)
For $oLink In $oLinks
If StringInStr($oLink, $pattern) Then
_IEAction($oLink, "click")
sleep(700)
_IEQuit($oIE)
ExitLoop
EndIf
Next
Basically what I need to achieve is,
if a $oLink in $oLinks contains $pattern - click on it.
The above program, for some reason, does not work.
Any suggestions?
Thank you
I'm not sure if you can use StringInStr on the object.
Try using:
StringInStr($oLink.href, $pattern)
instead.
Do you get your links with this piece of code?
#include <Array.au3>
#include <Inet.au3>
local $pattern = "/123/"
$source = _INetGetSource('https://www.nytimes.com/')
$links = StringRegExp($source, 'href="(http.*?)"', 3)
_ArrayDisplay($links)
Then you just need to adapt your For Next loop and use StringInStr on every links[$i]

SciTE Script - How to get inside a Tree Control to set checkboxes

I'm using AutoIt and SciTE to create an installation script. The problem I am running into is that there is a tree menu for selection of features. I can select the whole treeview (SysTreeView32), but am not sure how to get inside it to check the boxes without doing a mouse move and click (not a great option).
The Treeview looks like this:
The Control Info from AutoIT is like this:
I'm sure it is possible, just can't figure out how to do it. This is my first attempt a such a script. Creating a response file does not work for this exe for some reason. So - this appears to be my only way out to create a somewhat silent install (not silent anymore, but at least automated).
* EDIT - Current State of Things *
I did figure out how to do some of this, but I still can't figure out if the items is selected before accessing it. So - since it toggles, I could be turning off a feature I want!
$hWnd = WinWaitActive($WindowTitle, 'Select Features')
$tvCtl = ControlGetHandle($WindowTitle, '', 'SysTreeView321')
$firstItem = _GUICtrlTreeView_FindItem($tvCtl, 'eBooks')
_GUICtrlTreeView_SelectItem($tvCtl, $firstItem, $TVGN_FIRSTVISIBLE)
_GUICtrlTreeView_ClickItem($tvCtl, $firstItem, "left", True, 1)
Send('{SPACE}')
I wouldn't think I would have to send the space since I sent the ClickItem, but seems so.
I could also do this:
ControlTreeView($hWnd, '', $tvCtl, 'Select', '#0')
ControlSend($hWnd, '', $tvCtl, ' ')
That will toggle the first one. So - i can count them all up and do it that way.
But when I check for "IsEnabled" or "IsChecked", it always says NO. So - I can't check the ones I need only. I have to hope their status is what I expect.
Here is how I am checking "IsChecked" and "IsEnabled":
If ControlCommand($hWnd, '', $logTool, 'IsEnabled') then
ConsoleWrite('Log Tool - IsEnabled' & #CRLF)
Else
ConsoleWrite('Log Tool - NOTEnabled' & #CRLF)
EndIf
and
If ControlCommand($hWnd, '', $logTool, 'IsChecked') then
ConsoleWrite('Log Tool - IsChecked' & #CRLF)
Else
ConsoleWrite('Log Tool - NOTChecked' & #CRLF)
EndIf
It always comes back NOTEnabled and NOTChecked. I made sure that I ran the same procedure above: FindItem, SelectItem, ClickItem. And, the correct item is highlighted/selected when this procedure is run - I can see that. So - it just isn't returning a proper value.
Opt('WinTitleMatchMode', 2)
$hWnd = WinGetHandle("InstallShield Wizard") ; Notice the correct title
$hTree = ControlGetHandle($hWnd, '', "[CLASS:SysTreeView32;INSTANCE:1]")
; == Now you can interact with the treeview with functions from "GuiTreeView.au3"
EDIT:
Try this
; Select the item so:
_GUICtrlTreeView_SelectItem($hTree, $hItem, $TVGN_CARET)
; Get checked state:
_GUICtrlTreeView_GetChecked($hTree, $hItem)
For more deatails read the AutoIt help.

`ControlCommand` not working with `ComboLBox`

Instead of returning the currect selected font, it returns 0.
ShellExecute("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("!O")
Send("F")
WinWaitActive("Font")
$select = ControlCommand("Font", "", "[CLASS:ComboLBox; INSTANCE:1]", "GetCurrentSelection", "")
MsgBox(0,"", $select)
That control is actually a "Combo L Box", not a ComboBox. As the AutoIt helpfile says under ControlCommand:
Certain commands that work on normal Combo and ListBoxes do not work
on "ComboLBox" controls.
The ComboLBox is actually a child control of the ComboBox, and is just the drop down part of it. If you use a more advanced window finder like Spy++, you will actually see there is a ComboBox there, with two children (an Edit and the ComboLBox). So your code will work if you change "[CLASS:ComboLBox; INSTANCE:1]" to "[CLASS:ComboBox; INSTANCE:1]".
Furthermore, you can improve your code for triggering the menu item, so that the entire operation can be done in the background.
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Local $IDM_FONT = 33
Local $hWindow = WinGetHandle("Untitled - Notepad")
_WinAPI_PostMessage($hWindow, $WM_COMMAND, $IDM_FONT, 0)
Local $hFontWin = WinWait("Font")
$select = ControlCommand($hFontWin, "", "ComboBox1", "GetCurrentSelection", "")
WinClose($hFontWin)
MsgBox(0,"", $select)
Alternatively, you can interact with the ComboLBox in the same way you would a listbox:
$hLBox = ControlGetHandle($hFontWin, "", "ComboLBox1")
$itemIndex = _GUICtrlListBox_GetCurSel()
$select = _GUICtrlListBox_GetText($hLBox, $itemIndex)
Why ControlCommand doesn't work with this particular type of list box I have no idea. I can only guess that internally they check the control class against "ComboBox" and "ListBox" and return zero if there is no match.
You can use ControlGetText() to read the name of the currently active font, if this is what you want to accomplish.
ShellExecute("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("!O")
Send("F")
WinWaitActive("Font")
$select = ControlGetText("Font", "", "Edit1")
MsgBox(0,"", $select)

Can't retrieve links inside Frame

I am trying to use AutoIt to retrieve some data from this website:
http://www.acgme.org/adspublic/default.asp
Unfortunately, the page uses frames and I'm having trouble navigating to the page where the data is.
The link is "Accredited Programs"
#include <IE.au3>
$URL="http://www.acgme.org/adspublic/"
$MyIExplorer=_IECreate($URL,1,1,1,1)
Local $theFrame = _IEGetObjById($MyIExplorer,"control")
MsgBox(0,"The Frame",$theFrame.src)
Local $oLinks = _IELinkGetCollection($theFrame)
MsgBox(0, "Link Count", #extended & " links found")
When I run the code above, I am able to populate $theFrame with the correct frame object that houses the "Accredited Programs" link, but that's as far as I can get. The $oLinks collection comes back empty.
Frames are rather special. Use _IEFrameGetObjByName instead.
#include <IE.au3>
$URL="http://www.acgme.org/adspublic/"
$MyIExplorer=_IECreate($URL,1,1,1,1)
Local $theFrame = _IEFrameGetObjByName($MyIExplorer,"control")
Local $oLinks = _IELinkGetCollection($theFrame)
MsgBox(0, "Link Count", #extended & " links found")

Resources