Maxxx23 Posted January 25, 2020 Posted January 25, 2020 Hello @ Danp2 thank you for your great work. I have a problem where after a long search I have not found a solution. Unfortunately my English is not the best and I am still a beginner. I want to control a slider on a website. I tried folding code. 1. Code $Scale = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='scale']") Sleep(500) _WD_ElementAction($sSession, $Scale, 'value', 1) HTML <input type="range" step="0.01" min="0.01" max="1" name="scale" id="scale" class="scale-track-input" value="0.5038529934795495"><span class="scale-value"><!-- react-text: 2182 -->50<!-- /react-text --><!-- react-text: 2183 -->%<!-- /react-text --></span><div class="scale-track"></div> The error message __WD_Post: URL=HTTP://127.0.0.1:9515/session/2cad894bac9039cde17f47b11492b26c/element; $sData={"using":"xpath","value":"//input[@id='scale']"} __WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"a44b58dd-46c2-4ca1-b781-9122b5c9f5f6"}} _WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"a44b58dd-46c2-4ca1-b781-9122b5c9f5f6"}} __WD_Post: URL=HTTP://127.0.0.1:9515/session/2cad894bac9039cde17f47b11492b26c/element/a44b58dd-46c2-4ca1-b781-9122b5c9f5f6/value; $sData={"id":"a44b58dd-46c2-4ca1-b781-9122b5c9f5f6", "text":"1"} __WD_Post: StatusCode=200; ResponseText={"value":null} _WD_ElementAction: {"value":null} 2. I also tried to solve the problem with Mouseclick. But there are a lot of sliders so I would like to know which X Y position the input field has. So that I can process the value further. What code do I use to get the XY position (Pixel) of an HTML element? Unfortunately I have not found anything up to date. Thank you
Danp2 Posted January 25, 2020 Posted January 25, 2020 17 minutes ago, Maxxx23 said: The error message Those aren't error messages. They are just showing you the result for each command and it appears that each one completed successfully. From what I can tell, your code should work. You may want to try something like -- For $i = .01 to 1 Step .1 _WD_ElementAction($sSession, $Scale, 'value', $i) Sleep(500) Next P.S. Please stick to just one post / thread for each topic Latest Webdriver UDF Release Webdriver Wiki FAQs
Developers Jos Posted January 25, 2020 Developers Posted January 25, 2020 29 minutes ago, Danp2 said: P.S. Please stick to just one post / thread for each topic The other post is removed, so refrain from cross posting please! Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Maxxx23 Posted January 27, 2020 Author Posted January 27, 2020 On 1/25/2020 at 9:40 PM, Danp2 said: Those aren't error messages. They are just showing you the result for each command and it appears that each one completed successfully. From what I can tell, your code should work. You may want to try something like -- For $i = .01 to 1 Step .1 _WD_ElementAction($sSession, $Scale, 'value', $i) Sleep(500) Next P.S. Please stick to just one post / thread for each topic Thanks for your quick reply. Unfortunately, it doesn't work either. It happens exactly the same as with my code snippet.
Danp2 Posted January 27, 2020 Posted January 27, 2020 @Maxxx23 Unsure why _WD_ElementAction isn't working for this. In the mean time, I've found a way to do it when the site uses jQuery. Here's an example -- #include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession, $sElement, $sJsonElement SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://www.html5tutorial.info/html5-range.php") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='slider1']") $sJsonElement = '{"' & $_WD_ELEMENT_ID & '":"' & $sElement & '"}' For $i = 100 to 500 Step 10 _WD_ExecuteScript($sSession, "$(arguments[0]).val("&$i&").change()", $sJsonElement); Sleep(500) Next Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["--user-data-dir=C:\\Users\\' & @UserName & '\\AppData\\Local\\Google\\Chrome\\User Data\\", "--profile-directory=Default"]}}}}' EndFunc Func SetupGecko() _WD_Option('Driver', 'geckodriver.exe') _WD_Option('DriverParams', '--log trace') _WD_Option('Port', 4444) $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts":true}}}' EndFunc Latest Webdriver UDF Release Webdriver Wiki FAQs
Danp2 Posted January 27, 2020 Posted January 27, 2020 I found this -- https://github.com/web-platform-tests/wpt/issues/20734. Also this is the functionality being implemented in that portion of _WD_ElementAction -- https://www.w3.org/TR/webdriver/#element-send-keys So, it makes sense in hindsight that this doesn't work with input elements where you don't set their value by sending keystrokes. Looks like we'll need to use _WD_ExecuteScript to handle this for now. FYI, you should be able to do this without jQuery, ie -- _WD_ExecuteScript($sSession, "arguments[0].value="&$i&";", $sJsonElement) Latest Webdriver UDF Release Webdriver Wiki FAQs
Maxxx23 Posted January 28, 2020 Author Posted January 28, 2020 On 1/25/2020 at 9:13 PM, Maxxx23 said: @ Danp2 Thanks it works, the controller moves. Unfortunately it does not work on the desired homepage. This is probably due to the programming of the page.
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