Jump to content

Recommended Posts

Posted
3 hours ago, Nine said:

You are missing the keyup part :

$sAction = '{"actions":[{"type": "key", "id": "keyboard_1", "actions": [{"type": "keyDown", "value": "\uE006"}, {"type": "keyUp", "value": "\uE006"}]}]}'

Try 6 and 7 (return and enter)

I think aim doing this in a wrong way, found a question in this thread but the solution, was not clear:

this as to do with the select2 script, maybe using _WD_ExecuteScript to programmatically select an option, like Danp2 said?

 

My script at the moment:

;~ Author
local $lgnButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/div/div[1]/table/tbody/tr/td/div[2]/form/table/tbody/tr[8]/td[2]/div/span/span[1]/span/ul/li/input")

_WD_ElementAction($sSession, $lgnButton, 'click')
_WD_LoadWait($sSession, 3000)
$lgnButton1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@class='select2-search__field']")
_WD_ElementAction($sSession, $lgnButton1, 'value', "Dan Brown")

;~ _WD_Action($sSession, 'actions', '{"actions":[{"type": "key", "id": "keyboard_1", "actions": [{"type": "keyDown", "value": "\uE006"}, {"type": "keyUp", "value": "\uE006"}]}]}')
;~ _WD_Action($sSession, 'actions', '{"actions":[{"type": "key", "id": "keyboard", "actions": [{"type": "keyDown", "value": "\uE007"}, {"type": "keyUp", "value": "\uE007"}]}]}')

 

Posted (edited)

@Romano71 I'd like to confirm that it truly is a select2 element. Can you tell us the website URL or show us the HTML for this element?

FWIW, here's how to programmatically change the example select element on this page --

$('.js-example-basic-single').val('NC')
$('.js-example-basic-single').trigger('change')

You should be able to do it in a single _WD_ExecuteScript call --

_WD_ExecuteScript($sSession, "$('.js-example-basic-single').val('NC').trigger('change')")

 

Edited by Danp2
Add example
Posted

I cant get it to work, here is the code:

 

<tr>
                            <td class='heading'>
                                <span class='has-text-red'><b>* </b></span>Author<span class='has-text-red'><b> *</b></span>
                            </td>
                            <td>
                                <div class='round10'>
                                    <select class='select2-authors-multiple' name='author[]' id='author' multiple style='width: 100%;'></select>
                                </div><br>
                                
                            </td>
                        </tr>
                        <tr>

 

i have tried everything:

;~ Author
local $lgnButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/div/div[1]/table/tbody/tr/td/div[2]/form/table/tbody/tr[8]/td[2]/div/span/span[1]/span/ul/li/input")
;~ _WD_ElementAction($sSession, $lgnButton, 'value', "Dan Brown")
_WD_ExecuteScript($sSession, "$('.js-example-basic-single').val('NC').trigger('change')")
ConsoleWrite("Author1: " & @CRLF)
_WD_ElementAction($sSession, $lgnButton, 'click')
_WD_LoadWait($sSession, 3000)
_WD_ExecuteScript($sSession, "$('.js-example-basic-single').val('NC').trigger('change')")
ConsoleWrite("Author2: " & @CRLF)
$lgnButton1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@class='select2-search__field']")
_WD_ElementAction($sSession, $lgnButton1, 'value', "Dan Brown")
_WD_ExecuteScript($sSession, "$('.js-example-basic-single').val('NC').trigger('change')")
ConsoleWrite("Author3 " & @CRLF)
;~ _WD_Action($sSession, 'actions', '{"actions":[{"type": "key", "id": "keyboard_1", "actions": [{"type": "keyDown", "value": "\uE006"}, {"type": "keyUp", "value": "\uE006"}]}]}')
;~ _WD_Action($sSession, 'actions', '{"actions":[{"type": "key", "id": "keyboard", "actions": [{"type": "keyDown", "value": "\uE007"}, {"type": "keyUp", "value": "\uE007"}]}]}')

 

Posted
3 hours ago, Romano71 said:

I cant get it to work... i have tried everything

Apparently not. 😒

FYI, Select2 is a jQuery replacement for select boxes, so the solution I posted uses jQuery to find the desired element and update it in a single command.  The code is specific to the linked website. You should test it on that site, not yours. Once you confirmed that it works, then you need to adapt it to your own situation.

 

Posted

Of course you are right Thank you, i have altered the line and it worked:

_WD_ExecuteScript($sSession, "$('.select2-search__field').val('Dan Brown').trigger('change')")

now the problem is the wepage as 2 boxes like that and fills the 2 boxes(same name), i need to find a way alter that.

Posted (edited)
On 1/8/2021 at 2:32 PM, Danp2 said:

See https://www.w3.org/TR/webdriver/#print

This is implemented in _WD_Window with the 'print' option. I don't recall testing it, so your feedback would be appreciated. :thumbsup:

this goes a bit over my head. reading the definition for print and knowing how to call it correctly are two different things. This doesn't do a great job of telling you how to even use it. It tells you the pseudo logic for how its supposed to work, but not really what the parameters / types are, and what the result datatype is...or if it just saves the PDF for you?

 

Sorry if I'm a pain in the butt here, but calling print seems to do nothing. Still playing with it trying to figure out what's going on.

Edited by Cyphon68
Posted
9 minutes ago, Danp2 said:

I'm sure that's not true. 😒 What does the log in the Scite output panel look like?

Hint: At a minimum, you have to pass a empty JSON string (ie: '{}') for the $sOption parameter

using the following code:

_WD_Navigate($sSession, "http://www.amd.com")
_WD_Timeouts($sSession, '{"pageLoad":30000,"script":30000}')
_WD_Window($sSession,"print")

I get:

__WD_Post: URL=HTTP://127.0.0.1:9515/session/3e102a187391a7bcdca17e86cd9e8d92/url; $sData={"url":"http://www.amd.com"}
__WD_Post: StatusCode=200; ResponseText={"value":null}...
_WD_Navigate: {"value":null}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/3e102a187391a7bcdca17e86cd9e8d92/timeouts; $sData={"pageLoad":30000,"script":30000}
__WD_Post: StatusCode=200; ResponseText={"value":null}...
_WD_Timeouts: {"value":null}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/3e102a187391a7bcdca17e86cd9e8d92/print; $sData=
__WD_Post: StatusCode=404; ResponseText={"value":{"error":"unknown command","message":"unknown command: unknown command: session/3e102a18739...
__WD_Post ==> Unknown Command: {"value":{"error":"unknown command","message":"unknown command: unknown command: session/3e102a187391a7bcdca17e86cd9e8d92/print","stacktrace":"Backtrace:\n\tOrdinal0 [0x00F09563+2725219]\n\tOrdinal0 [0x00E08551+1672529]\n\tOrdinal0 [0x00CF0359+525145]\n\tOrdinal0 [0x00C9920E+168462]\n\tOrdinal0 [0x00C99074+168052]\n\tOrdinal0 [0x00C7235E+9054]\n\tOrdinal0 [0x00C727C6+10182]\n\tOrdinal0 [0x00C72E50+11856]\n\tOrdinal0 [0x00E1D607+1758727]\n\tGetHandleVerifier [0x01026546+1050150]\n\tGetHandleVerifier [0x01026291+1049457]\n\tGetHandleVerifier [0x010310D7+1094071]\n\tGetHandleVerifier [0x01026B46+1051686]\n\tOrdinal0 [0x00E15B06+1727238]\n\tOrdinal0 [0x00C72213+8723]\n\tOrdinal0 [0x00C71F20+7968]\n\tGetHandleVerifier [0x011FDC8C+2981228]\n\tBaseThreadInitThunk [0x76B26359+25]\n\tRtlGetAppContainerNamedObjectPath [0x76F98944+228]\n\tRtlGetAppContainerNamedObjectPath [0x76F98914+180]\n"}}
_WD_Window: {"value":{"error":"unknown command","message":"unknown command: unknown command: session/3e102a18739...
_WD_Window ==> Unknown Command: HTTP status = 404

which looks like "print" is an unknown command? 

 

Just so i'm not copying my entire output, the startup looks like this:

_WD_IsLatestRelease: False
_WD_IsLatestRelease ==> Success
_WDStartup: OS: WIN_10 WIN32_NT 18362 
_WDStartup: AutoIt: 3.3.14.5
_WDStartup: WD.au3: 0.3.1.0 (Update available)
_WDStartup: WinHTTP:    1.6.4.2
_WDStartup: Driver: chromedriver.exe
_WDStartup: Params: --verbose --log-path="C:\Users\...path goes here...\chrome.log"
_WDStartup: Port:   9515

 

Posted

What version of Chrome / chromedriver? With 87.0.4280.88 for both I get this --

__WD_Post: URL=HTTP://127.0.0.1:9515/session/78fae68c462a02fccdf75396445a957c/print; $sData=
__WD_Post: StatusCode=400; ResponseText={"value":{"error":"invalid argument","message":"invalid argument: missing command parameters","stack...
__WD_Post ==> Invalid argument: {"value":{"error":"invalid argument","message":"invalid argument: missing command parameters","stacktrace":"Backtrace:\n\tOrdinal0 [0x00C2C0C3+3326147]\n\tOrdinal0 [0x00B10851+2164817]\n\tOrdinal0 [0x00997298+619160]\n\tOrdinal0 [0x0092F8AB+194731]\n\tOrdinal0 [0x0092F3A5+193445]\n\tOrdinal0 [0x00902244+8772]\n\tOrdinal0 [0x00902746+10054]\n\tOrdinal0 [0x00902DA1+11681]\n\tOrdinal0 [0x00B285DC+2262492]\n\tGetHandleVerifier [0x00DB2874+1487204]\n\tGetHandleVerifier [0x00DB23CD+1486013]\n\tGetHandleVerifier [0x00DBA368+1518680]\n\tGetHandleVerifier [0x00DB2F4E+1488958]\n\tOrdinal0 [0x00B1ED0D+2223373]\n\tOrdinal0 [0x00901FB2+8114]\n\tOrdinal0 [0x00901976+6518]\n\tGetHandleVerifier [0x00FA187C+3514732]\n\tBaseThreadInitThunk [0x76CFFA29+25]\n\tRtlGetAppContainerNamedObjectPath [0x77BF75F4+228]\n\tRtlGetAppContainerNamedObjectPath [0x77BF75C4+180]\n"}}
_WD_Window: {"value":{"error":"invalid argument","message":"invalid argument: missing command parameters","stack...
_WD_Window ==> Invalid argument: HTTP status = 400

and I already gave you the solution to that in my earlier post.

P.S. I've got it working on my end with Firefox. This will require a few minor changes to the UDF.

Posted (edited)

You need to click on password first then it will show the SHOW/HIDE button.  Both have unique ids.  To find those ids, right click on password field and select "Inspect" in contextual menu.

To remove it try :

_WD_ExecuteScript($sSession, "return document.getElementById('id_password_toggle').remove();", "")

 

Edited by Nine
Posted
15 hours ago, Danp2 said:

What version of Chrome / chromedriver? With 87.0.4280.88 for both I get this --

__WD_Post: URL=HTTP://127.0.0.1:9515/session/78fae68c462a02fccdf75396445a957c/print; $sData=
__WD_Post: StatusCode=400; ResponseText={"value":{"error":"invalid argument","message":"invalid argument: missing command parameters","stack...
__WD_Post ==> Invalid argument: {"value":{"error":"invalid argument","message":"invalid argument: missing command parameters","stacktrace":"Backtrace:\n\tOrdinal0 [0x00C2C0C3+3326147]\n\tOrdinal0 [0x00B10851+2164817]\n\tOrdinal0 [0x00997298+619160]\n\tOrdinal0 [0x0092F8AB+194731]\n\tOrdinal0 [0x0092F3A5+193445]\n\tOrdinal0 [0x00902244+8772]\n\tOrdinal0 [0x00902746+10054]\n\tOrdinal0 [0x00902DA1+11681]\n\tOrdinal0 [0x00B285DC+2262492]\n\tGetHandleVerifier [0x00DB2874+1487204]\n\tGetHandleVerifier [0x00DB23CD+1486013]\n\tGetHandleVerifier [0x00DBA368+1518680]\n\tGetHandleVerifier [0x00DB2F4E+1488958]\n\tOrdinal0 [0x00B1ED0D+2223373]\n\tOrdinal0 [0x00901FB2+8114]\n\tOrdinal0 [0x00901976+6518]\n\tGetHandleVerifier [0x00FA187C+3514732]\n\tBaseThreadInitThunk [0x76CFFA29+25]\n\tRtlGetAppContainerNamedObjectPath [0x77BF75F4+228]\n\tRtlGetAppContainerNamedObjectPath [0x77BF75C4+180]\n"}}
_WD_Window: {"value":{"error":"invalid argument","message":"invalid argument: missing command parameters","stack...
_WD_Window ==> Invalid argument: HTTP status = 400

and I already gave you the solution to that in my earlier post.

P.S. I've got it working on my end with Firefox. This will require a few minor changes to the UDF.

chrome = 83.0.4103.97

chromedriver = 83.0.4103.39

I'm sorry, I'm not trying to be difficult here. I can follow function definitions pretty well, or if there's some example code that's working, I can solve nearly everything on my own. When you say you already answered it, you mean when you posted passing an empty JSON string for the parameter? Cause that just throws a different error that arguments are missing, which makes sense, as it should need at least where you want to save the PDF.

I think you've done great work here with the UDF, but this print function isn't really documented well from the chromedriver, so I'm running into issues. 🤷‍♂️

Posted

@Cyphon68 That version of chrome is over 6 months old, so your issue may have been resolved in a later release. From my testing, the webdriver print functionality will return a base64 encoded string, which then needs to be decoded and written to disk.

There is also a limitation in the current Chrome implementation that requires it to be running in headless mode for the print function to work. See here for details. FWIW, I haven't confirmed that it works with Chrome in headless mode.

Firefox is confirmed working with just the empty JSON string. When I have some time, I'll try to figure out some of the other options.

Posted

I am sorry i have tried everything, how to adjust the selector so that it uniquely identifies the desired element. i now this is as Javascript issue but i am zero at javascript.

this works but fill both forms:

_WD_ExecuteScript($sSession, "$('.select2-search__field').val('Dan Brown').trigger('change')")

From firefox inspector i get this:

<input class="select2-search__field" type="search" tabindex="0" autocomplete="off" autocorrect="off" autocapitalize="none" spellcheck="false" role="searchbox" aria-autocomplete="list" placeholder="Select an Author" style="width: 1251.9px;">

<input class="select2-search__field" type="search" tabindex="0" autocomplete="off" autocorrect="off" autocapitalize="none" spellcheck="false" role="searchbox" aria-autocomplete="list" placeholder="Select a Narrator" style="width: 1241.9px;">

the html code:

<div class='round10'>
<select class='select2-authors-multiple' name='author[]' id='author' multiple style='width: 100%;'></select>

<div class='round10'>
<select class='select2-narrators-muliple' name='narrator[]' id='narrator' multiple='multiple' style='width: 100%;'></select>

 

Posted

You can add an additional attribute to the jQuery selector to further limit the matching elements. For example --

_WD_ExecuteScript($sSession, "$('.select2-search__field[placeholder=""Select an Author""]').val('Dan Brown').trigger('change')")

I may not have the quotation marks correct, but you should get the gist of it.

Not sure this will work, but you could also try using the element name or ID from the HTML you posted.

Posted (edited)

Hi autoit community,

I want to be able to check the status of a check box, to find if it is checked or unchecked, but if I try 

_WD_ElementAction($sSession, $element, 'Selected')

no mater if the item is checked or unchecked it returns false.

So far I tried 

Attribute
Property
Value

with no luck.

Is there any other way to find the status of the checked or unchecked box ?

PS : if I use 

Click

on the checkbox, it is clicked. 

Edited by Siwa
Posted (edited)
2 hours ago, Siwa said:

I want to be able to check the status of a check box

It would've helped if you showed the relevant HTML in order to give you a more accurate answer.  So instead, I will show you based on the following:

Assuming a web page has a checkbox defined as:  (example taken from the "Remember Me" checkbox on https://www.autoitscript.com/forum/login/)

<input type="checkbox" name="remember_me" id="remember_me_checkbox" value="1" checked="" aria-checked="true">

In order to see whether the checkbox is checked, you can check its "checked" property by doing something like:

$idElement = _WD_FindElement($gsSession, $_WD_LOCATOR_ByXPath, "//input[@id='remember_me_checkbox']")
ConsoleWrite("Checkbox Checked = " & _WD_ElementAction($gsSession, $idElement, "property", "checked") & @CRLF)

Which in my case displays:

Checkbox Checked = True

 

Edited by TheXman
Changed from checking attribute to property
Posted

Unfortunately it did not work.

here is the checkbox inspect (its located in a table):

Unchecked : 

<tr data-ri="28" class="ui-widget-content ui-datatable-even textGreenBold" role="row" xpath="1"><td role="gridcell" style="text-align:center;width: 5% !important; padding: 1px 1px !important;"><div id="dataTable:28:j_idt248" class="ui-chkbox ui-widget"><div class="ui-helper-hidden-accessible"><input id="dataTable:28:j_idt248_input" name="dataTable:28:j_idt248_input" type="checkbox" autocomplete="off" aria-checked="false" onchange="PrimeFaces.ab({s:&quot;dataTable:28:j_idt248&quot;,e:&quot;valueChange&quot;,p:&quot;dataTable:28:j_idt248&quot;,u:&quot;formNurse&quot;,g:false});"></div><div class="ui-chkbox-box ui-widget ui-corner-all ui-state-default"><span class="ui-chkbox-icon ui-icon ui-c ui-icon-blank"></span></div></div></td><td role="gridcell" style="text-align:center;white-space: normal;"><span class="titleBnazanin" style="color:red;font-weight: bold;" title="جمعه">جمعه</span></td><td role="gridcell" style="text-align:center"><span class="titleBnazanin">1399/11/10</span></td><td role="gridcell" style="text-align:center;white-space: normal;"><span class="titleBnazanin">2.0</span></td><td role="gridcell" style="text-align:center;white-space: normal;"><span class="titleBnazanin">مصرف اصل</span></td><td role="gridcell" style="text-align:center;white-space: normal;"><span class="titleBnazanin">بلی</span></td><td role="gridcell" style="text-align:center;white-space: normal;"><span class="no"></span></td><td role="gridcell" style="text-align:center"><span class="titleBnazanin">1399/10/29 17:21:05</span></td></tr>
Checked :

<tr data-ri="28" class="ui-widget-content ui-datatable-even textGreenBold" role="row" xpath="1"><td role="gridcell" style="text-align:center;width: 5% !important; padding: 1px 1px !important;"><div id="dataTable:28:j_idt248" class="ui-chkbox ui-widget"><div class="ui-helper-hidden-accessible"><input id="dataTable:28:j_idt248_input" name="dataTable:28:j_idt248_input" type="checkbox" autocomplete="off" aria-checked="false" onchange="PrimeFaces.ab({s:&quot;dataTable:28:j_idt248&quot;,e:&quot;valueChange&quot;,p:&quot;dataTable:28:j_idt248&quot;,u:&quot;formNurse&quot;,g:false});"></div><div class="ui-chkbox-box ui-widget ui-corner-all ui-state-default ui-state-active"><span class="ui-chkbox-icon ui-icon ui-c ui-icon-check"></span></div></div></td><td role="gridcell" style="text-align:center;white-space: normal;"><span class="titleBnazanin" style="color:red;font-weight: bold;" title="جمعه">جمعه</span></td><td role="gridcell" style="text-align:center"><span class="titleBnazanin">1399/11/10</span></td><td role="gridcell" style="text-align:center;white-space: normal;"><span class="titleBnazanin">2.0</span></td><td role="gridcell" style="text-align:center;white-space: normal;"><span class="titleBnazanin">مصرف اصل</span></td><td role="gridcell" style="text-align:center;white-space: normal;"><span class="titleBnazanin">بلی</span></td><td role="gridcell" style="text-align:center;white-space: normal;"><span class="no"></span></td><td role="gridcell" style="text-align:center"><span class="titleBnazanin">1399/10/29 17:21:05</span></td></tr>

here is the element itself :

Unchecked :

<div class="ui-chkbox-box ui-widget ui-corner-all ui-state-default" xpath="1"><span class="ui-chkbox-icon ui-icon ui-c ui-icon-blank"></span></div>
Checked :

<div class="ui-chkbox-box ui-widget ui-corner-all ui-state-default ui-state-active" xpath="1"><span class="ui-chkbox-icon ui-icon ui-c ui-icon-check"></span></div>

Here is the element with chropath :

Unchecked :

//tr[29]//td[1]//div[1]//div[2]
Chhecked :

//div[contains(@class,'ui-chkbox-box ui-widget ui-corner-all ui-state-default ui-state-active')]

Sorry I forgot to write the code befor.

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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