Jump to content

WebDriver UDF - Help & Support (II)


Danp2
 Share

Recommended Posts

1 minute ago, Retaki said:

how can i know if the _WD_FindElement has found the required element?

Check the value of @error, like this --

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "\\your\xpath\here")

    If @error = $_WD_ERROR_SUCCESS Then
        _WD_ElementAction($sSession, $sElement, 'click')
    EndIf

P.S. You should definitely review the function header for each of the UDF functions. I've tried to outline the return values and error codes for each one, but let me know if you find where any of the information is missing / incorrect.

Link to comment
Share on other sites

36 minutes ago, Danp2 said:

@HCD_Boy Yes... you need to pass your desired arguments as part of the DesiredCapabilities string when calling _WD_CreateSession. For Chrome, see information here regarding the "args" option under ChromeOptions.

Thanks for very quick response!

Unfortunately,  Webdriver accepts the code, but the output doesn't work... I just see the normal Chrome (Microsoft Edge) window, as I start it without the "app-id" argument. Any ideas?

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"ms:edgeOptions": {"args":["app-id=mkjkjhffnfhefonpoajpeaohoocodfig"], "w3c": true, "useAutomationExtension": false}}}}'

Output of chrome.log-File:

Quote

[1585321355.891][INFO]: Starting MSEdgeDriver 80.0.361.50 (c54b8bed30dc6f775d2c35c6330fa1d7b470afaf) on port 9515
[1585321355.903][INFO]: Please protect ports used by MSEdgeDriver and related test frameworks to prevent access by malicious code.
[1585321356.310][INFO]: [ff679ada30b66e1076e7fe3ae6be8109] COMMAND InitSession {
   "capabilities": {
      "alwaysMatch": {
         "ms:edgeOptions": {
            "args": [ "app-id=mkjkjhffnfhefonpoajpeaohoocodfig" ],
            "useAutomationExtension": false,
            "w3c": true
         }
      }
   }
}
[1585321356.327][INFO]: Populating Preferences file: {
   "alternate_error_pages": {
      "enabled": false
   },
   "autofill": {
      "enabled": false
   },
   "browser": {
      "check_default_browser": false
   },
   "distribution": {
      "import_bookmarks": false,
      "import_history": false,
      "import_search_engine": false,
      "make_chrome_default_for_user": false,
      "skip_first_run_ui": true
   },
   "dns_prefetching": {
      "enabled": false
   },
   "profile": {
      "content_settings": {
         "pattern_pairs": {
            "https://*,*": {
               "media-stream": {
                  "audio": "Default",
                  "video": "Default"
               }
            }
         }
      },
      "default_content_setting_values": {
         "geolocation": 1
      },
      "default_content_settings": {
         "geolocation": 1,
         "mouselock": 1,
         "notifications": 1,
         "popups": 1,
         "ppapi-broker": 1
      },
      "password_manager_enabled": false
   },
   "safebrowsing": {
      "enabled": false
   },
   "search": {
      "suggest_enabled": false
   },
   "translate": {
      "enabled": false
   }
}
[1585321356.342][INFO]: Populating Local State file: {
   "background_mode": {
      "enabled": false
   },
   "ssl": {
      "rev_checking": {
         "enabled": false
      }
   }
}
[1585321356.353][INFO]: Cannot switch to US keyboard layout - some keys may be interpreted incorrectly
[1585321356.369][INFO]: Launching msedge: "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --app-id=mkjkjhffnfhefonpoajpeaohoocodfig --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --enable-automation --enable-blink-features=ShadowDOMV0 --enable-logging --log-level=0 --no-first-run --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir="C:\Users\***\AppData\Local\Temp\scoped_dir77380_811997869" data:,
[1585321358.384][INFO]: resolved localhost to ["::1","127.0.0.1"]
[1585321359.420][INFO]: [ff679ada30b66e1076e7fe3ae6be8109] RESPONSE InitSession {
   "capabilities": {
      "acceptInsecureCerts": false,
      "browserName": "msedge",
      "browserVersion": "80.0.361.66",
      "ms:edgeOptions": {
         "debuggerAddress": "localhost:58324"
      },
      "msedge": {
         "msedgedriverVersion": "80.0.361.50 (c54b8bed30dc6f775d2c35c6330fa1d7b470afaf)",
         "userDataDir": "C:\\Users\\***\\AppData\\Local\\Temp\\scoped_dir77380_811997869"
      },
      "networkConnectionEnabled": false,
      "pageLoadStrategy": "normal",
      "platformName": "windows",
      "proxy": {

      },
      "setWindowRect": true,
      "strictFileInteractability": false,
      "timeouts": {
         "implicit": 0,
         "pageLoad": 300000,
         "script": 30000
      },
      "unhandledPromptBehavior": "dismiss and notify"
   },
   "sessionId": "ff679ada30b66e1076e7fe3ae6be8109"
}
 

 

Link to comment
Share on other sites

6 minutes ago, HCD_Boy said:

Thanks for very quick response!

Unfortunately,  Webdriver accepts the code, but the output doesn't work... I just see the normal Chrome (Microsoft Edge) window, as I start it without the "app-id" argument. Any ideas?

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"ms:edgeOptions": {"args":["app-id=mkjkjhffnfhefonpoajpeaohoocodfig"], "w3c": true, "useAutomationExtension": false}}}}'

Output of chrome.log-File:

 

I got something: It has to be something with the 1000 arguments given at "Launching msedge". Until argument "--disable-popup-blocking" it starts well with "Run" from Windows. I have to find the bad argument. Give me some minutes.

Link to comment
Share on other sites

14 minutes ago, HCD_Boy said:

I got something: It has to be something with the 1000 arguments given at "Launching msedge". Until argument "--disable-popup-blocking" it starts well with "Run" from Windows. I have to find the bad argument. Give me some minutes.

Well to use the "app-id" argument, you have to specify the default "user-data-dir" of your Chrome! (in my case: "C:\Users\***\AppData\Local\Microsoft\Edge\User Data")

Link to comment
Share on other sites

<tr role="row" class="even" id="Weight"><td>Weight</td><td>WEIGHT</td><td>ai4</td><td><a href="#" onclick="gsSettings.sensorsDialog('244829');" title="Edit"><i class="fa fa-edit fa-lg fa-operations"></i></a><a href="#" onclick="gsSettings.sensorsDelete('244829');" title="Delete"><i class="fa fa-trash-o fa-lg fa-operations"></i></a><a href="#" onclick="gsSettings.sensorsClone('244829');" title="Clone to other objects"><i class="fa fa-trash-o fa-lg fa-clone"></i></a></td></tr>

How i can retrive these (<td>) values? its not a value the text is written inside <td> and i want to make sure that am selecting the correct element? 

so how i can i select the (<tr>) element based on one of its <td> text?

Link to comment
Share on other sites

1 hour ago, HCD_Boy said:

Well to use the "app-id" argument, you have to specify the default "user-data-dir" of your Chrome!

Well... that makes sense when you take into account this earlier statement --

Quote

I have a web application, similar WhatsApp Web. I added this Website to "Apps" in Chrome.

So this "app-id" won't exist unless you are using your normal user profile.

Link to comment
Share on other sites

@Retaki I suggest that you open a new topic requesting help because this feels more like an xpath question rather than something specific to this UDF. ☺️

P.S. Be sure to include enough details so that we can better understand what you are trying to accomplish, and show us any code you've written thus far in attempts to solve the issue.

 

Link to comment
Share on other sites

@Retaki These are various actions that can be performed by the _WD_ElementAction function. Examples of some of these can be found in wd_demo.au3.

If you are receiving the message "Invalid data type" when calling _WD_ElementAction, then you are most likely passing the wrong value for the $sCommand parameter.

Link to comment
Share on other sites

On 3/27/2020 at 10:38 PM, HCD_Boy said:

Well to use the "app-id" argument, you have to specify the default "user-data-dir" of your Chrome! (in my case: "C:\Users\***\AppData\Local\Microsoft\Edge\User Data")

i have send link in my comment about send argr. 
i thing youhave to use like this
 

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"ms:edgeOptions": {"args":["--app-id=mkjkjhffnfhefonpoajpeaohoocodfig"], "w3c": true, "useAutomationExtension": false}}}}'

 

Edited by VodkaDiva

xxxxxxxxxxx

Link to comment
Share on other sites

@VodkaDiva Don't believe that's needed, because the log they posted contained this --

[1585321356.369][INFO]: Launching msedge: "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --app-id=mkjkjhffnfhefonpoajpeaohoocodfig --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --enable-automation --enable-blink-features=ShadowDOMV0 --enable-logging --log-level=0 --no-first-run --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir="C:\Users\***\AppData\Local\Temp\scoped_dir77380_811997869" data:,

You would need to test your method to make sure that this works as well.

Link to comment
Share on other sites

Sory i just want to help. 
Hi dan . i have read chromedriver.chromium.org . but don't know how to java transfer to autoit . can you see and help me ? thanks a lot ! 
Java here 

Map<String, String> mobileEmulation = new HashMap<>();

mobileEmulation.put("deviceName", "Nexus 5");

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);

or python here

from selenium import webdriver

mobile_emulation = { "deviceName": "Nexus 5" }

chrome_options = webdriver.ChromeOptions()

chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)

when use autoit i use here but it notworking . Thanks dan

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions":{"prefs": {"intl.accept_languages": "'&$NgonNgu&'"},"mobileEmulation":{"deviceName":" Galaxy S5"},"w3c":true, "args":["--blink-settings=imagesEnabled=true"] }}}}'

 

xxxxxxxxxxx

Link to comment
Share on other sites

Hello!

Sorry for noobie questions that were asked 1000 times already, but I'm trying my best w/o actual knowledge.

I made "manual" script for myself to do some repetitive "copy&paste" tasks. Problem is that it occupies PC. So in attempt to make it run in background run into this solution, but new problems arrived.

1) New user profile in browsers when using webdriver, that is stripped of useful extensions.  Every freaking site shoves "Updated terms" or "Cookies" messages that ruins scripts. So

On 3/27/2020 at 6:38 PM, HCD_Boy said:

Well to use the "app-id" argument, you have to specify the default "user-data-dir" of your Chrome! (in my case: "C:\Users\***\AppData\Local\Microsoft\Edge\User Data")

how to do that? I understand that you can google examples, but not for this particular thing, even if expressions are the same. Where to define it, in SetupChrome function in $sDesiredCapabilities? My profile is in default location "C:\Users\username\AppData\Local\Google\Chrome\User Data\Default", so can somebody who uses his own profile help with this?

2) Since I need to loop same actions just with different hyperlinks from same site I thought it would be best just to use clipboard to get address from list in excel/libre doc and loop the whole thing. But when I tried using Clipget for navigation

Local $sData = ClipGet() 

_WD_Navigate($sSession, $sData)

it didn't work. Maybe it's dumb way to do it, but hope you can explain how to do

-copy address from spreadsheet

-navigate to it

-copy stuff, click stuff, screenshot stuff, move screen around

-paste it to spreadsheet

-go to address+1 and repeat

better. Don't care about formatting data on the fly or stuff like that, just want it copied w/o occupying PC and I will do formatting/analytics in spreadsheet later

3) I figured out how to find elements (buttons, etc) with XPath, but sometimes it produces error. Chrome/FF both copy XPath with " " and it needs to be ' ' in autoit, right? There's no difference in _WD_Navigate, but I had to manually change it couple of times to make it work for FindElement.

Also, how do I simulate something like 

MouseClickDrag($MOUSE_CLICK_LEFT, 165, 400, 1100, 450)

to select cluster of data. Site always formats data the same way, so I just need to navigate to proper element location and copy them all together(I format&convert in spreadsheet). Is there way to use Ctrl to make this selection in background, or I will need to find all the elements I need through XPath and copy the value?

Thanks in advance for any help

Link to comment
Share on other sites

@grablestyp See the following wiki entry for how to specify an existing user profile -- https://www.autoitscript.com/wiki/WebDriver#FAQ

Everything else -- Provide more details so that we can better know how to assist you. Show us the contents of your spreadsheet. Give more details on the data you want to retrieve from the website, etc.

Link to comment
Share on other sites

57 minutes ago, Danp2 said:

See the following wiki entry for how to specify an existing user profile -- https://www.autoitscript.com/wiki/WebDriver#FAQ

Thanks, that worked. It would be my suggestion to add those to example/demo file and also explain that it requires fresh start. Helps to intuitively understand stuff, even if you're not supposed to do it that way.  SetupBrowser functions are small enough to have couple additional rows. Tried that method 

but it didn't work for me, had to close browser and give script a fresh start for it to work.

1) Done

2) Is it possible to use ClipGet in _WD_Navigate($sSession, data copied to clipboard)? Or any other way for "data copied to clipboard -> becomes address to navigate" task. ClipGet didn't work for me. I have huge list of links (1k+) and need to go through all of them and do the same task. I guess my question is: what's best method to do it? In manual script I just used "Click down to go one row to the bottom and copy same A1 cell by location" caveman method. How do I do it in background&simpler?

3) Does _WD_FindElement require ' instead of " in XPath copied from browser's element inspection? Is there difference between:

$sElement=_WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='live-match-options']/li[3]/a/span[2]")

$sElement=_WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id="live-match-options"]/li[3]/a/span[2]") (that's how browsers copy XPath)

I get errors with 2nd and no errors with 1st. Just want clarification.

4) And is there other way to copy clustered data from page, instead of copying 1 by 1? Data changes depending on category you clicked:

https://i.imgur.com/poGS1pa.png

https://i.imgur.com/PDApAX2.png

So can you use matching elements example for it

; Locate multiple matching elements

$aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div/input", '', True)
 _ArrayDisplay($aElements, "Found Elements")

Or it's better to just cluster copy it like I used to with MouseDrag

https://i.imgur.com/OywEEB7.png

Because if you have to copy them 1-by-1 and paste to spreadsheet, it will probably take more time (even with insane speed instead of user actions imitation), than to copy all at once and sort it later in spreadsheet (I already have sorting prepared, just need to paste data in proper cells). I don't care about speed or neat/optimized code that much. Just want it to work in background.

5) Any way to check if page is loaded instead of relying on sleep/pause? I saw third party methods that use plugins and JS status and read it to identify status in IF...ELSE function. Now that annoying cookies&updated terms disappeared because of proper chrome profile, I still have problem of loading to quickly or slow (1st launch/1st site visit) and my provider sometimes inserting info page into browser.

Basically, my short question would be: how to "IF object exists continue ELSE pause" using WD functionality? 

 

Link to comment
Share on other sites

  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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