MRAJ Posted December 21, 2020 Posted December 21, 2020 Hello, I was searching the exact match for WinWait in WebDriver UDF functions. I tried with _wd_loadwait,_wd_windows & _wd_Attach but no success. I need to match with Title and class with windows info as we find using finder tool. I tried with attached script but it is not giving required results like if page title or windows info not found then results in Error. expandcollapse popup#include "wd_core.au3" #include "wd_helper.au3" $_WD_DEBUG = $_WD_DEBUG_None Local $sDesiredCapabilities, $sSession, $sElement SetupEdge() _WD_Startup() Sleep(2000) $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession,"$URL") Local $sLoad = _WD_LoadWait($sSession,5) ;Tried with wd_attach ;_WD_Attach($sSession,'Work - Microsoft Edge') ;If @error = $_WD_ERROR_Success Then ; LogError(" Success & $URL) ;Else ; $ScreenShot = _WD_Screenshot($sSession) ; $FileName = "Test.jpg" ; $FilePath = FileOpen("filepath" & $dTimeStamp & $FileName) ;FileWrite($FilePath, $ScreenShot) ;FileClose($FilePath) ;_WD_DeleteSession($sSession) ;_WD_Shutdown() If $sLoad = 0 Then LogError(" Success & $URL) Else $ScreenShot = _WD_Screenshot($sSession) $FileName = "Test.jpg" $FilePath = FileOpen("filepath" & $dTimeStamp & $FileName) FileWrite($FilePath, $ScreenShot) FileClose($FilePath) _WD_DeleteSession($sSession) _WD_Shutdown() EndIf Func SetupEdge() _WD_Option('Driver', 'msedgedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--verbose') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"ms:edgeOptions": {"binary": "' & StringReplace (@ProgramFilesDir, "\", "/") & '/Microsoft/Edge/Application/msedge.exe", "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false}}}}' EndFunc _WD_DeleteSession($sSession) _WD_Shutdown()
Danp2 Posted December 21, 2020 Posted December 21, 2020 Your script isn't runnable as posted, and I'm finding it difficult to understand -- what you are trying to accomplish why you "need to match with Title and class with windows info" when using webdriver Please provide further details so that we can better understand your goals. Latest Webdriver UDF Release Webdriver Wiki FAQs
MRAJ Posted December 21, 2020 Author Posted December 21, 2020 Hello Dan, I just want to match with the title or class of the website page and alert like if the page not matching with info or class, it should give error results. I used to do for my IE scripts and it was working fine. For example: Example() Func Example() ; Run Notepad Run("notepad.exe") ; Wait 10 seconds for the Notepad window to appear. WinWait("[CLASS:Notepad]", "", 10) ; Wait for 2 seconds to display the Notepad window. Sleep(2000) ; Close the Notepad window using the classname of Notepad. WinClose("[CLASS:Notepad]") EndFunc ;==>Example Local $hWnd = WinWait("Windows info Ttile using Finder Tool","",5) WinActivate($hWnd) Sleep(2000) If $hWnd = 0 Then MsgBox($MB_SYSTEMMODAL, "Title", "", 10) Else LogError("Success & $URL) EndIf
Danp2 Posted December 21, 2020 Posted December 21, 2020 I understand why you would need this for the example you posted. However, I fail to see why you would need to use "class" in conjunction with webdriver. Maybe something with URL or title, which is what _WD_Attach offers. Anyway, it doesn't sound like the function you want already exists. Latest Webdriver UDF Release Webdriver Wiki FAQs
MRAJ Posted December 22, 2020 Author Posted December 22, 2020 Hello Dan, I just took a simple script to check for _wd_attach but it is taking always Else statement only. Attached is the script. i also changed to If @error <> $_WD_ERROR_Success but it will take always If statement only, even website will fail. I am not sure if i am wrong in my script or _wd_attach syntax part missing something. expandcollapse popup#include "wd_core.au3" #include "wd_helper.au3" #include <MsgBoxConstants.au3> $_WD_DEBUG = $_WD_DEBUG_None Local $sDesiredCapabilities, $sSession, $sElement SetupEdge() _WD_Startup() Sleep(2000) $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession,"https://www.google.com/") _WD_Attach($sSession,"Google - Work - Microsoft? Edge") If @error = $_WD_ERROR_Success Then MsgBox($MB_SYSTEMMODAL, "Title", "Google working") Else MsgBox($MB_SYSTEMMODAL, "Title", "Google not working") EndIf Func SetupEdge() _WD_Option('Driver', 'msedgedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--verbose') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"ms:edgeOptions": {"binary": "' & StringReplace (@ProgramFilesDir, "\", "/") & '/Microsoft/Edge/Application/msedge.exe", "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false}}}}' EndFunc _WD_DeleteSession($sSession) _WD_Shutdown()
Danp2 Posted December 22, 2020 Posted December 22, 2020 Hi @MRAJ, A few comments / thoughts in response to your post -- Like I said before, the function you want doesn't yet exist _WD_Attach is the wrong function to use unless you are wanting to switch to a different tab For debugging your script, stop setting $_WD_DEBUG = $_WD_DEBUG_None If you check the value of "document.title" in the developer console, you will find that the value is "Google" not "Google - Work - Microsoft? Edge" Frankly, it still isn't clear to me why you need this function. After all, your script is controlling the navigation and you can test for success / failure of that. Have you checked out the function _WD_WaitElement? It can come in handy when you need to make sure a page has fully loaded or you need to check for a specific element. HTH, Dan Latest Webdriver UDF Release Webdriver Wiki FAQs
MRAJ Posted December 22, 2020 Author Posted December 22, 2020 Thanks Dan. Only i was thinking to check the full page of the website without finding the particular element in the page, using the title in the finder tool and it will give me an success/failure if the page gives out put like page can't displayed or any http error etc. i will try with Navigate function and find element.
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