Jump to content

New to this. Need help WebDriver UDF | Chrome


Recommended Posts

Hi Guys, 

im sry to ask u, but im very new to this and im trying to figure out, how i can automate a anoying thing on my work.

Its costs me nearly a whole day, just for a few steps, cause i have to stay on my computer to press some buttons, so it doesnt stop.

I made it work to login with WebDriver UDF and now i have to find the right Buttons and press them. 

I tried to to this with this:

Func _WD_LinkClickByText($sSession, $sText, $lPartial = True)
    Local Const $sFuncName = "_WD_LinkClickByText"

    Local $sElement = _WD_FindElement($sSession, ($lPartial) ? $_WD_LOCATOR_ByPartialLinkText : $_WD_LOCATOR_ByLinkText, $sText)

    Local $iErr = @error

    If $iErr = $_WD_ERROR_Success Then
        _WD_ElementAction($sSession, $sElement, 'click')
        $iErr = @error

        If $iErr <> $_WD_ERROR_Success Then
            Return SetError(__WD_Error($sFuncName, $_WD_ERROR_Exception), $_WD_HTTPRESULT)
        EndIf
    Else
        Return SetError(__WD_Error($sFuncName, $_WD_ERROR_NoMatch), $_WD_HTTPRESULT)
    EndIf

    Return SetError($_WD_ERROR_Success)
EndFunc

But it allways says:

"C:\Users\...au3" (25) : ==> Duplicate function name.:
Func _WD_LinkClickByText($sSession, $sText, $lPartial = True)

Would be awesome if someone could help me :D 

Thx Guys!

Link to comment
Share on other sites

That function is present in the include wd_helper.au3

If you use (have copied) that function in your own script too, there will be 2 functions with the same name, therefore, duplicate.

In order to call that function you don't need to copy it into your script, you just call it

_WD_LinkClickByText($sSession, $sText, True)

replacing the variables in there with the variables or values as needed.

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

I allrdy did this. Thx for ur help!

Maybe u can help me to find out, how to change the tab know. The Link opens a new tab, but now i cant  use the function (presslinkbytext) to press the next link, cause it seems it isn't in focus for the WebDriver. 

Link to comment
Share on other sites

u r insanly awesome! 

Found it! 

Next Problem :D :

Is there a way to let a mouse clik by text not by link? 

Cause i have a text, which is a link, but doesnt get recognized as link. So i have to find a way around this!

Link to comment
Share on other sites

Yes... you would use _WD_FindElement to first get a reference to the desired element. Then pass that information to _WD_ElementAction with the "click" command. This is essentially what _WD_LinkClickByText does, so you can review its functionality for an example. You would just need to use different criteria to find the desired element.

Link to comment
Share on other sites

U mean this, right?

_WD_ElementOptionSelect($sSession, $sStrategy, $sSelector[, $sStartElement = ""])

Has this to look like this?

_WD_ElementOptionSelect($sSession, $sStrategy, $sSelector["ao"], $sStartElement = "ario"])

Sry, to annoy you! Im very nooby!

Edited by Bosco
Link to comment
Share on other sites

THis doesnt work:

_WD_ElementOptionSelect($sSession, $_WD_LOCATOR_ByXPath, "//*[@id="project"]), ario[, $sStartElement = " - Projekt - "])

Any suggestions?

Edited by Bosco
Link to comment
Share on other sites

Your syntax is still way off. I see several things to correct --

  • You need to fix your usage of quotes. If you have a string delimited with double quotes, then use single quotes inside the string. For example --
"//*[@id='project']"
  • You have an errant close parentheses right after your xpath string
  • Suggest that you remove the following as it is all wrong --
    , asspario[, $sStartElement = " - Projekt - "]

P.S. It might make it easier to help you if you provided the HTML for the elements you are trying to access

Link to comment
Share on other sites

I try to select ario from the dropdown with the id project :

<select name="project" id="project" onchange="javascript:document.frmk_pr.submit()" style="width:auto"><option value="" style="color: gray;">– Projekt –</option><option value="lnpwfKc_">ario</option></option></select>

Edited by Bosco
Link to comment
Share on other sites

Awesome :D

So now i changed this to select the next one, which works good, if i choose it like this:

_WD_ElementOptionSelect($sSession, $_WD_LOCATOR_ByXPath, "//select[@name='rollback_bodi']//option[2]")

But when i try to choose the first option like this:

_WD_ElementOptionSelect($sSession, $_WD_LOCATOR_ByXPath, "//select[@name='rollback_bodi']//option[1]")

It doesnt work.

<select name="rollback_bodi" onchange="loadCheckbox(this.value);">
            <option value="" style="color: silver">bitte waehlen</option>
        <optgroup label=""><option value="233" style="">233  |  01.05.2020 – 31.05.2020</option><option value="" style="color: silver">231  |  01.05.2020 – 31.05.2020</option><option value="" style="color: silver">230  |  01.05.2020 – 31.05.2020</option><option value="" style="color: silver">229  |  01.04.2020 – 30.04.2020</option><option value="" style="color: silver">228  |  01.04.2020 – 30.04.2020</option></select>

Any Ideas why? I have to choose the Top1 Option cause it changes every month!

 

Found a way around this:

Using this now!

_WD_ElementOptionSelect($sSession, $_WD_LOCATOR_ByXPath, "//select[@name='rollback_bodi']")
Send ("{down}")
Send ("{Enter}")


 

Edited by Bosco
Link to comment
Share on other sites

Im sry, if im asking to much. But for me its totally new and quite hard to find my way through this.

But i think im on a good way, so hopefully u r still rdy to help me!

After i selected the dropdown with this:

_WD_ElementOptionSelect($sSession, $_WD_LOCATOR_ByXPath, "//select[@name='rollback_bodi']")
Send ("{down}")
Send ("{Enter}")

i want to select the Number infront of the Date, in this example: "230"

<option value="230" style="">230  |  01.05.2020 – 31.05.2020</option>

and save it, to use it later.

i now i could identify it by this part:

<option value="230" style="">

cause the other options, r like this: (now value between "" and no color!

<option value="" style="color: silver"></option>

But how can i do this?

Edited by Bosco
Link to comment
Share on other sites

Mixing standard Autoit commands (like Send) with the Webdriver functions is not a recommended solution. Also, stating "doesn't work" without providing any additional details makes it difficult to know how to guide you.

My recommendation is to be sure you are running with $_WD_DEBUG = $_WD_DEBUG_Info. That way, you get the maximum output in the Scite console panel. When you encounter an issue, show us your code and the associated debugging details so that we can help diagnose the situation.

Link to comment
Share on other sites

When i use these:

_WD_ElementOptionSelect($sSession, $_WD_LOCATOR_ByXPath, "//select[@name='rollback_bodi']//option[1]")

this happens:

__WD_Post: URL=HTTP://127.0.0.1:9515/session/b2f19455cb9e09f37947f7687ce46d02/element; $sData={"using":"xpath","value":"//select[@name='rollback_bodi']//option[1]"}
__WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"98129d35-94ec-4dd4-ad68-43d2d275dd7b"}}...
_WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"98129d35-94ec-4dd4-ad68-43d2d275dd7b"}}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/b2f19455cb9e09f37947f7687ce46d02/element/98129d35-94ec-4dd4-ad68-43d2d275dd7b/click; $sData={"id":"98129d35-94ec-4dd4-ad68-43d2d275dd7b"}
__WD_Post: StatusCode=200; ResponseText={"value":null}...
_WD_ElementAction: {"value":null}...

But there isnt anything selected:

grafik.png.0ce2ac25d3c9c1b072c12487ba23a2bb.png

But when i use this:

_WD_ElementOptionSelect($sSession, $_WD_LOCATOR_ByXPath, "//select[@name='rollback_bodi']//option[2]")

It selects the second entry:

grafik.png.876b2911818e1f1626bd9e69c310dcb1.png

Link to comment
Share on other sites

28 minutes ago, Bosco said:

But there isnt anything selected

Not true. The output you posted shows that the code executed successfully. Also, if you go back and review the HTML you posted previously, the first option listed is "bitte waehlen". So you are selecting the first option, which tells you to "please select" an option. 😃

Quote

It selects the second entry:

That's actually the 3rd entry if you count the "please select" one. I wonder if this is caused by the use of the optgroup element? Perhaps the xpath needs to be adjusted to account for that.

Link to comment
Share on other sites

Sry im stupid:

/html/body/center/div/table/tbody/tr[2]/td[2]/div/table/tbody/tr[2]/td/div/div[4]/form[2]/select

this is the xpath i get.

 

Edited by Bosco
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...