Jump to content

WebDriver UDF geckodriver browser is not displaying all elements on page as regular FireFox browser


Go to solution Solved by Danp2,

Recommended Posts

Posted

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

#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

ย 

Romaji Not Showing 0001-0001-0001.jpg

Posted

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.

Posted

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)

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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