Bosco Posted June 5, 2020 Share Posted June 5, 2020 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 Thx Guys! Link to comment Share on other sites More sharing options...
careca Posted June 5, 2020 Share Posted June 5, 2020 (edited) 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 June 5, 2020 by careca Danp2 1 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 More sharing options...
Bosco Posted June 5, 2020 Author Share Posted June 5, 2020 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 More sharing options...
Danp2 Posted June 5, 2020 Share Posted June 5, 2020 Take a look at _WD_Attach, also in wd_helper.au3 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Bosco Posted June 5, 2020 Author Share Posted June 5, 2020 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 More sharing options...
Danp2 Posted June 5, 2020 Share Posted June 5, 2020 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. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Bosco Posted June 6, 2020 Author Share Posted June 6, 2020 Okay guys, worked since i changed the name to recognize and click link worked! With this i can choose a specific entry in a dropdownlist? Link to comment Share on other sites More sharing options...
Danp2 Posted June 6, 2020 Share Posted June 6, 2020 ; Name ..........: _WD_ElementOptionSelect ; Description ...: Find and click on an option from a Select element Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Bosco Posted June 6, 2020 Author Share Posted June 6, 2020 (edited) 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 June 7, 2020 by Bosco Link to comment Share on other sites More sharing options...
Danp2 Posted June 6, 2020 Share Posted June 6, 2020 Nope... not even close. 😃 Use the forum search feature to search for examples of using _WD_ElementOptionSelect. If you can't find one, then check out some for _WD_FindElement (the syntax is similar). Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Bosco Posted June 8, 2020 Author Share Posted June 8, 2020 (edited) THis doesnt work: _WD_ElementOptionSelect($sSession, $_WD_LOCATOR_ByXPath, "//*[@id="project"]), ario[, $sStartElement = " - Projekt - "]) Any suggestions? Edited June 8, 2020 by Bosco Link to comment Share on other sites More sharing options...
Danp2 Posted June 8, 2020 Share Posted June 8, 2020 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 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Bosco Posted June 8, 2020 Author Share Posted June 8, 2020 (edited) 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 June 8, 2020 by Bosco Link to comment Share on other sites More sharing options...
Danp2 Posted June 8, 2020 Share Posted June 8, 2020 Should work with the correct xpath. Try this -- _WD_ElementOptionSelect($sSession, $_WD_LOCATOR_ByXPath, "//select[@name='project']//option[contains(text(),'ario')]") Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Bosco Posted June 8, 2020 Author Share Posted June 8, 2020 (edited) Awesome 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 June 8, 2020 by Bosco Link to comment Share on other sites More sharing options...
Bosco Posted June 8, 2020 Author Share Posted June 8, 2020 (edited) 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 June 8, 2020 by Bosco Link to comment Share on other sites More sharing options...
Danp2 Posted June 8, 2020 Share Posted June 8, 2020 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. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Bosco Posted June 8, 2020 Author Share Posted June 8, 2020 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: But when i use this: _WD_ElementOptionSelect($sSession, $_WD_LOCATOR_ByXPath, "//select[@name='rollback_bodi']//option[2]") It selects the second entry: Link to comment Share on other sites More sharing options...
Danp2 Posted June 8, 2020 Share Posted June 8, 2020 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. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Bosco Posted June 8, 2020 Author Share Posted June 8, 2020 (edited) 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 June 8, 2020 by Bosco Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now