Jump to content

Recommended Posts

Posted (edited)

I'm trying to use ControlSetText in AutoIt to input text into the "Name" and "Fuzzy Name" fields on this web page:
๐Ÿ‘‰ https://www.trade.gov/data-visualization/csl-search

However, it doesn't seem to work. I suspect it's because the page uses modern web technologies (JavaScript-based elements), and maybe ControlSetText can't interact with them properly.

I tried inspecting the elements and using their IDs, but I'm still stuck. I'm very new to this, so I'd really appreciate any help or guidance. Here's the code I'm working with:

<input type="text" class="explorer__form__input" id="name" name="name" value="">
<input type="text" class="explorer__form__input" id="name" name="name" value="">
#include <AutoItConstants.au3>
; Open the browser and navigate to the URL
Run("C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe https://www.trade.gov/data-visualization/csl-search")
WinWaitActive("CSL Search") ; Wait for the window title

Sleep(5000)

; Try to set the text in the "Name" field
ControlSetText("CSL Search", "CSL Search - International Trade Administration", "name", "Kromlรผks")

Sleep(500)

 

Edited by mustilem23
Posted

The above method is the correct one
However, there is also the beginner's method. :)
 

;~ Opt("SendKeyDelay", 100) ; Slow motion

; Open the browser and navigate to the URL
Run("C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe https://www.trade.gov/data-visualization/csl-search")

Local $hWnd = WinWaitActive("CSL Search", "", 5) ; Wait Max 5 sec for the window title

If $hWnd Then
    Send("{TAB 19}") ; go to the name field
    Send("Kromlรผks") ; set the name

    Send("{TAB 5}") ; go to the search button
    Send("{ENTER}") ; execute the search
Else
    ConsoleWrite("I can't find the 'CSL Search' window." & @CRLF)
EndIf

 

I know that I know nothing

  • Moderators
Posted

Moved to the appropriate AutoIt General Help and Support forum, as the Developer General Discussion forum very clearly states:

  Quote

General development and scripting discussions.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Expand  

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)
  On 4/22/2025 at 12:57 PM, ioa747 said:

Yukarฤฑdaki yรถntem doฤŸru olanฤฑdฤฑr
Ancak, baลŸlangฤฑรง yรถntemi de vardฤฑr.
:)
 

;~ Opt("SendKeyDelay", 100) ; Slow motion

; Open the browser and navigate to the URL
Run("C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe https://www.trade.gov/data-visualization/csl-search")

Local $hWnd = WinWaitActive("CSL Search", "", 5) ; Wait Max 5 sec for the window title

If $hWnd Then
    Send("{TAB 19}") ; go to the name field
    Send("Kromlรผks") ; set the name

    Send("{TAB 5}") ; go to the search button
    Send("{ENTER}") ; execute the search
Else
    ConsoleWrite("I can't find the 'CSL Search' window." & @CRLF)
EndIf

 

Expand  

Thank you very much for your support. I was actually using a similar scenario myself, but in a video I saw that itโ€™s possible to interact with websites using element IDs, which is why Iโ€™ve started researching this approach.

I don't have much coding knowledge, but as you can see, my current scenario isnโ€™t very complex. I plan to improve and develop it further later on.

Edited by mustilem23
Posted
  On 4/25/2025 at 12:06 PM, mustilem23 said:

in a video I saw that itโ€™s possible to interact with websites using element IDs

Expand  

it may be an old video ? It may not apply to 2025 :(

  On 4/25/2025 at 12:06 PM, mustilem23 said:

don't have much coding knowledge, but as you can see, my current scenario isnโ€™t very complex.

Expand  

yes, and you'll need to use what @nine told you.

  On 4/25/2025 at 12:06 PM, mustilem23 said:

I plan to improve and develop it further later on.

Expand  

..later on today, this week, as an entry in a bucket list ? :D

I'd personally do what @ioa747 told you ( in code ) and add send Ctrl-A to select all, then Ctrl-C to copy to clipboard the text.
Because I never used the WebDriver and this copy and paste is easier to a new coder ( you ). Admittedly the WebDriver is the better approach if you know what you're doing.

And seeing what you did on the other thread you show to be very inexperienced, hence this commentary to you.

Ok, good luck and have fun :) 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted (edited)

Here to start you up.  This is meant to show you that it is not complicated to accomplish what you want :

#include "wd_helper.au3"

Local $sDesiredCapabilities = SetupChrome()
_WD_Startup()
Local $sSession = _WD_CreateSession($sDesiredCapabilities)

_WD_Navigate($sSession, "https://www.trade.gov/data-visualization/csl-search")
_WD_FrameEnter($sSession, 0)
Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='name']")
ConsoleWrite($sElement & @CRLF)
_WD_ElementAction($sSession, $sElement, 'value', "Test")

;_WD_DeleteSession($sSession)
_WD_Shutdown()

Func SetupChrome()
  _WD_Option('Driver', 'chromedriver.exe')
  _WD_Option('Port', 9515)
  _WD_Option('DriverParams', '--port=9515 --verbose --log-path="' & @ScriptDir & '\chrome.log"')
  Return '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": ["enable-automation"]}}}}'
EndFunc   ;==>SetupChrome

 

Edited by Nine
Posted
  On 4/25/2025 at 3:50 PM, Nine said:

This is meant to show you that it is not complicated to accomplish what you want

Expand  

As long as @mustilem23 knows all the dependencies of the au3WebDriver (WebDriver) project ๐Ÿคญ . But yes, you're right (like so often), it's not that complicated as long as the documentation is read and understood. At least for the start.

Best regards
Sven

==> AutoIt related: ๐Ÿ”— GitHub, ๐Ÿ”— Discord Server, ๐Ÿ”— Cheat Sheet

  Reveal hidden contents

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
ร—
ร—
  • Create New...