JugglingCoder Posted March 1 Posted March 1 Please see the image and code below. In Short WebDriver UDF geckodriver browser is not displaying all elements as regular FireFox browser Details My code is working fine... 1.) it opens the geckodriver 2.) navigates to the translate page, 3.) copy/paste the text, 4.) and it translates into Kanji just fine. However... using the geckodriver browser, the "Romaji" (the English letters/words showing how to say the Kanji in English) text/element is missing.ย Using a regular browser and translating the text works fine and does show the "Romaji". Anybody have any input as to why this is happening?ย Am I missing a "_WD_Option" or "_WD_CapabilitiesAdd" that needs to be added? My goal for this little app was to get the Romaji but was very surprised to see... it's not there. Code expandcollapse popup#include <Constants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> ; ; =========== WEB_DRIVER_UDF_INCLUDES ================================================= #include "udf\wd_helper.au3" #include "udf\wd_capabilities.au3" #include "udf\wd_core.au3" Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase Global $sCapabilities ; NEEDED for the GeckoDriver Global $sSession ; NEEDED for the GeckoDriver Global $website = "https://translate.google.co.jp/?hl=en&sl=en&tl=ja" Global $string_to_translate = "The weather is nice today" #comments-start Standard FireFox URL - WORKS, i.e. Romaji Shows https://translate.google.co.jp/?hl=en&sl=en&tl=ja&text=The%20weather%20is%20nice%20today&op=translate Webdriver URL - Same exact URL but Romaji does NOT show https://translate.google.co.jp/?hl=en&sl=en&tl=ja&text=The%20weather%20is%20nice%20today&op=translate #comments-end SetupGecko() _WD_Startup() If @error <> $_WD_ERROR_Success Then Exit MsgBox(0, "Error", "Firefox Driver failed to load") $sSession = _WD_CreateSession($sCapabilities) If @error Then ConsoleWrite("Error Creating Session: " & @error & " Exiting." & @CRLF) MsgBox( $MB_TOPMOST, "Error Creating Session: ", & @error) Exit EndIf sleep(1000) _WD_Navigate($sSession, $website) ; opens a webpage (online or local) > Works WinWaitActive("Google Translate") ClipPut ($string_to_translate) Send("^v") ; "paste" into Google Translate Window #Region FUNCTION_DECLARATION #comments-start ================== Function Declarations START ========================= ============================================================= #comments-end Func SetupGecko() _WD_Option('Driver', 'udf\geckodriver.exe') Local $iPort = _WD_GetFreePort(4444, 4500) ; instead of specifing a specific port, this function will find a free port from one of the ports listed _WD_Option('Port', $iPort) _WD_CapabilitiesStartup() _WD_CapabilitiesAdd('alwaysMatch', 'firefox') _WD_CapabilitiesAdd('browserName', 'firefox') _WD_CapabilitiesAdd('acceptInsecureCerts', True) _WD_CapabilitiesAdd("prefs","browser.link.open_newwindow",2) ; WORKED!! Saw the "prefs" example on this page > https://www.autoitscript.com/wiki/WebDriver_Capabilities#Firefox_Examples $sCapabilities = _WD_CapabilitiesGet() Return $sCapabilities EndFunc ; SetupGecko #comments-start ================== Function Declarations END ========================== ============================================================= #comments-end #EndRegion #Region CLEANUP #comments-start ================== Cleanup START ================================= ============================================================= ; Currently not cleaning up so can inspect open window #comments-end ;_WD_DeleteSession($sSession) ;_WD_ShutDown() #EndRegion ;Exit ย
Solution Danp2 Posted March 1 Solution Posted March 1 You can thanks Google for this. They are modifying the behavior of the website when the browser has been launched via the webdriver. IIRC, there isn't a known way to bypass this. You may want to search the forum for past discussions. Latest Webdriver UDF Release Webdriver Wiki FAQs
JugglingCoder Posted March 2 Author Posted March 2 Thank you for your reply Danp2.ย Well... that sucks;(ย Thought there would be a simple solution.ย I did search quite a bit (always do before posting) and I'll try some more.
SOLVE-SMART Posted March 5 Posted March 5 Hi folks, hi @JugglingCoderย ๐, for chromedriver it is the same behavior, but can by bypassed with this additional argument option: "--disable-blink-features=AutomationControlled" { "capabilities":{ "alwaysMatch":{ "acceptInsecureCerts":true, "goog:chromeOptions":{ "w3c":true, "excludeSwitches":[ "enable-automation" ], "args":[ "--no-default-browser-check", "--disable-search-engine-choice-screen", "--disable-blink-features=AutomationControlled" ] } } } } Simply use: _WD_CapabilitiesAdd('args', '--disable-blink-features=AutomationControlled') โ But there is no official bypass for Firefox as far as I know and I didn't found any possibility. -------------------------- ๐ก If you really need this "Romaji" information, switch to chrome or msedge (chromium based browsers). Best regards Sven ==> AutoIt related: ๐ GitHub, ๐ Discord Server Spoiler ๐ย Au3Forums ๐ฒ AutoIt (en) Cheat Sheet ๐ AutoIt limits/defaults ๐ Code Katas: [...] (comming soon) ๐ญ Collection of GitHub users with AutoIt projects ๐ย False-Positives ๐ฎย Me on GitHub ๐ฌย Opinion about new forum sub category ๐ย UDF wiki list โย VSCode-AutoItSnippets ๐ย WebDriver FAQs ๐จโ๐ซย WebDriver Tutorial (coming soon)
JugglingCoder Posted Tuesday at 10:49 AM Author Posted Tuesday at 10:49 AM Great, thanksย SOLVE-SMART! I will give that code a try in the future and keep note of it.ย However, I was anxious so just simply switched to Bing Translate which worked fine with the geckodriver. SOLVE-SMART 1
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