Jump to content

Recommended Posts

  • Solution
Posted (edited)

Hi @argumentumย ๐Ÿ‘‹ ,

your page do not have any @ids in the DOM available (at least for the /LoginForm/ page. So you have to search for indicators which will give you the correct elements to interact with. In this example page you could use the placeholder attribute for username and password and the name "Login" for the submit button as your selectors.

In other words, you can use XPath for the three elements to interact (2x input, 1x button) like this:

_Login()

Func _Login()
    Local Const $sUsername = 'argumentum'
    Local Const $sPassword = 'your-password'

    Local Const $sUsernameSelector     = '//form//input[@placeholder="Enter Username"]' ; or by name: [@name="uname"]
    Local Const $sPasswordSelector     = '//form//input[@placeholder="Enter Password"]' ; or by name: [@name="psw"]
    Local Const $sSubmitButtonSelector = '//form//button[text()="Login"]'

    _WD_ElementAction($sSession, _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sUsernameSelector), 'value', $sUsername)
    _WD_ElementAction($sSession, _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sPasswordSelector), 'value', $sPassword)
    _WD_ElementAction($sSession, _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sSubmitButtonSelector), 'click')
EndFunc

I didn't tested it right now, but I am relatively sure, this should work ๐Ÿ˜‡ .

How did I came up with the XPath? Okay, I am experienced with locator strategies, but in case you're not:
Use Chrome (or Firefox) > right click on your target element > choose "inspect" > you are now in the DevTools ("Elements" tab) > right click on the highlighted DOM element (input or button) > choose Copy from the context menu > Copy XPath > Ctrl+F > paste your generated XPath in the search (optional) > this verifies the match > use this selector in the _WD_FindElement() function.

But: This is often not very robust. It's usually better to improve the selector by the usage of a relative XPath (different XPath Axes).

I hope this will answer your questions ๐Ÿคž .

Best regards
Sven

Edited by SOLVE-SMART

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

Spoiler

๐ŸŒย Au3Forums

๐ŸŽฒ AutoIt (en) Cheat Sheet

๐Ÿ“Š AutoIt limits/defaults

๐Ÿ’Ž Code Katas: [...] (comming soon)

๐ŸŽญ Collection of GitHub users with AutoIt projects

๐Ÿžย False-Positives

๐Ÿ”ฎย Me on GitHub

๐Ÿ’ฌย Opinion about new forum sub category

๐Ÿ“‘ย UDF wiki list

โœ‚ย VSCode-AutoItSnippets

๐Ÿ“‘ย WebDriver FAQs

๐Ÿ‘จโ€๐Ÿซย WebDriver Tutorial (coming soon)

Posted

These wrapper functions, of my boilerplate repository (regarding the au3WebDriver) could be helpful for further tasks you may have ๐Ÿ˜€ .

Best regards
Sven

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

Spoiler

๐ŸŒย Au3Forums

๐ŸŽฒ AutoIt (en) Cheat Sheet

๐Ÿ“Š AutoIt limits/defaults

๐Ÿ’Ž Code Katas: [...] (comming soon)

๐ŸŽญ Collection of GitHub users with AutoIt projects

๐Ÿžย False-Positives

๐Ÿ”ฎย Me on GitHub

๐Ÿ’ฌย Opinion about new forum sub category

๐Ÿ“‘ย UDF wiki list

โœ‚ย VSCode-AutoItSnippets

๐Ÿ“‘ย WebDriver FAQs

๐Ÿ‘จโ€๐Ÿซย WebDriver Tutorial (coming soon)

Posted
5 hours ago, argumentum said:

I added IDs to each <input> so it can be done with ID too.

Even better ๐Ÿ‘Œ , then you only need to search for this unique attribute //input[@id="idUName"], in case of the username. But I guess you already get it ๐Ÿ˜‡ .
Best regards
Sven

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

Spoiler

๐ŸŒย Au3Forums

๐ŸŽฒ AutoIt (en) Cheat Sheet

๐Ÿ“Š AutoIt limits/defaults

๐Ÿ’Ž Code Katas: [...] (comming soon)

๐ŸŽญ Collection of GitHub users with AutoIt projects

๐Ÿžย False-Positives

๐Ÿ”ฎย Me on GitHub

๐Ÿ’ฌย Opinion about new forum sub category

๐Ÿ“‘ย UDF wiki list

โœ‚ย VSCode-AutoItSnippets

๐Ÿ“‘ย WebDriver FAQs

๐Ÿ‘จโ€๐Ÿซย WebDriver Tutorial (coming soon)

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...