AutoIt Script how to interact with Chrome (login, copy text from a webpage into a box)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements

Welcome Idira to LIVEcommunity!

Our community just got stronger! Explore new identity security resources, connect with experts, and discover more ways to learn and collaborate.

Meet Idira

AutoIt Script how to interact with Chrome (login, copy text from a webpage into a box)

L4 Transporter

Hello,

With AutoIt I can interact with Internet Explorer, but when it comes with Chrome, the only way I found was with:

  1. Support of Python (using selenium (pip install selenium/ from selenium import webdriver) )
  2. or using direct Send("XYZ") to enter username and Send("{TAB}") ;

 

It seems I can't contact Chrome Directly like Internet Explorer, to search input field (by its ID) or extract an element (extract the text from the <h1 class="post-title"> element)

 

For example https://practicetestautomation.com/practice-test-login/ with AutoIT I can use Internet Explorer ( But for Chrome it seems impossibile to interact, unless I use python or a direct send)

 

Is there a way to write the below script but with Chrome?

 

 

 

; Create the COM object for Internet Explorer

Global $oIE = ObjCreate("InternetExplorer.Application")

 

; Navigate to the URL

$oIE.Navigate("https://practicetestautomation.com/practice-test-login/")

 

; Find the username input field (by its ID)

Local $oUsernameField = $oIE.document.getElementById("username")

If IsObj($oUsernameField) Then

  $oUsernameField.value = "student" ; Enter your username here

Else

  MsgBox(0, "Error", "Username field not found!")

  Exit

EndIf

 

; Find the password input field (by its ID)

Local $oPasswordField = $oIE.document.getElementById("password")

If IsObj($oPasswordField) Then

  $oPasswordField.value = "Password123" ; Enter your password here

Else

  MsgBox(0, "Error", "Password field not found!")

  Exit

EndIf

 

; Find and click the Submit button (by its ID)

Local $oSubmitButton = $oIE.document.getElementById("submit")

If IsObj($oSubmitButton) Then

  $oSubmitButton.Click() ; Click the submit button

Else

  MsgBox(0, "Error", "Submit button not found!")

  Exit

EndIf

 

; Now, extract the text from the <h1 class="post-title"> element

Local $oTitleElement = $oIE.document.getElementsByClassName("post-title")

 

If IsObj($oTitleElement) And $oTitleElement.length > 0 Then

  ; Extract the text from the <h1 class="post-title">

  Local $sMessage = $oTitleElement.item(0).innerText

   

  ; Copy the extracted text to the clipboard

  ClipPut($sMessage)

   

  ; , display the copied text in a message box

  MsgBox(0, "Success Message", "The message copied to clipboard is: " & @CRLF & $sMessage)

Else

  MsgBox(0, "Error", "Could not find the success message!")

EndIf

 

Thank you very much

1 accepted solution

Accepted Solutions

L7 Applicator

Hi @ABDOU LAZEZ HUSSIEN EL SHEREDI​ 

 

The AutoIt team has created a WebDriver UDF that supports Chrome, Firefox, Edge, etc.

 

https://www.autoitscript.com/forum/topic/191990-webdriver-udf

 

https://www.autoitscript.com/forum/topic/212240-webdriver-for-chrome/

 

With this UDF you can write almost the same style code as Selenium. It gives you Chrome automation without switching programming language.

 

Hope it helps!

 

View solution in original post

2 REPLIES 2

L7 Applicator

Hi @ABDOU LAZEZ HUSSIEN EL SHEREDI​ 

 

The AutoIt team has created a WebDriver UDF that supports Chrome, Firefox, Edge, etc.

 

https://www.autoitscript.com/forum/topic/191990-webdriver-udf

 

https://www.autoitscript.com/forum/topic/212240-webdriver-for-chrome/

 

With this UDF you can write almost the same style code as Selenium. It gives you Chrome automation without switching programming language.

 

Hope it helps!

 

@Malhar Vora​ 

Thank you appreciated! I will try it

  • 1 accepted solution
  • 107 Views
  • 2 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!