Jump to content

How do you type in this type of boxes by using WebDriver?


Go to solution Solved by Danp2,

Recommended Posts

testSlask()

Func testSlask()
    OtworzLink("http://www.raciborz.slaskie-ogloszenia.pl/ogloszeniaslaskie/dodaj")
    Uzupelnij("//input[@id='titlepl_PL']","//body[@class='mceContentBody ']","","//input[@id='contactEmail']","","","","")
    _WD_Shutdown()
    EndFunc

Func OtworzLink($sLink)
        _WD_Startup()
    $sSession = _WD_CreateSession($sDesiredCapabilities)
    _WD_Navigate($sSession, $sLink)
    _WD_LoadWait($sSession, 2000)
    EndFunc

Func OgloszenieReadOpen()
        Global $hFileOpen = FileOpen($sFilePathOgloszenie, $FO_READ)
    Global $sFileRead = FileRead($hFileOpen)
    $sFileRead = StringReplace($sFileRead, @CRLF, '\r\n')
EndFunc



Func _WD_SetElementValueNew($sSession, $sElement, $sValue, $iStyle = Default)
    Local Const $sFuncName = "_WD_SetElementValue"
    Local $sResult, $iErr, $sScript, $sJsonElement

    If $iStyle = Default Then $iStyle = $_WD_OPTION_Standard
    If $iStyle < $_WD_OPTION_Standard Or $iStyle > $_WD_OPTION_Advanced Then $iStyle = $_WD_OPTION_Standard

    Switch $iStyle
        Case $_WD_OPTION_Standard
            $sResult = _WD_ElementAction($sSession, $sElement, 'value', $sValue)
            $iErr = @error

        Case $_WD_OPTION_Advanced
            $sScript = "Object.getOwnPropertyDescriptor(arguments[0].__proto__, 'value').set.call(arguments[0], arguments[1]);arguments[0].dispatchEvent(new Event('input', { bubbles: true }));"
            $sJsonElement = '{"' & $_WD_ELEMENT_ID & '":"' & $sElement & '"}'
            $sResult = _WD_ExecuteScript($sSession, $sScript, $sJsonElement & ',"' & $sValue & '"')
            $iErr = @error

    EndSwitch

Func Uzupelnij($sXPtytul, $sXPogloszenie, $sXPwymagania, $sXPemail, $sXPfirma, $sXPwynagrodzenie, $sXPtelefon, $sXPnazwa)
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sXPogloszenie) ;ogloszenie
    OgloszenieReadOpen()
    _WD_SetElementValueNew($sSession, $sElement, $sFileRead, $_WD_OPTION_Advanced)
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sXPtytul) ;tytul
    TytulReadOpen()
    _WD_SetElementValueNew($sSession, $sElement, $sFileRead, $_WD_OPTION_Advanced)
    EndFunc


 

Edited by Jos
Added codebox
Link to comment
Share on other sites

  • Developers
8 minutes ago, AnnoyingClown said:

sorry it took so long, tried to make it readable for you

just read the post source page :)

Edited by 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.
  :)

Link to comment
Share on other sites

11 minutes ago, Danp2 said:

Yes, the code for SetElementValue was updated on May 8th, and this enhancement was included in the latest release (v0.4.0.4). See my signature for the link to the latest version.

Ok, I downloaded and tested it, I still need to use ElementValueNew and replace my @CRLF with \r\n

Link to comment
Share on other sites

@Danp2 Yep that was my bad that ElementValueNew didn't work, fixed it for now, And
 

Func testSlask()
    Local $sTestElement
    OtworzLink("http://www.raciborz.slaskie-ogloszenia.pl/ogloszeniaslaskie/dodaj")
    OgloszenieReadOpen()
        $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iframe[@id='descriptionpl_PL_ifr']")
    _WD_FrameEnter($sSession, $sElement)
    $sTestElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//body[@id="tinymce"]')
    _WD_SetElementValue($sSession, $sTestElement, $sFileRead)
    _WD_Shutdown()
    EndFunc

Func OgloszenieReadOpen()
        Global $hFileOpen = FileOpen($sFilePathOgloszenie, $FO_READ)
    Global $sFileRead = FileRead($hFileOpen)
    $sFileRead = StringReplace($sFileRead, @CRLF, '\r\n')
    Global $hFileOpen = FileOpen($sFilePathOgloszenie, $FO_READ)
    $sOgloszenieReadOpen = FileRead($hFileOpen)
    EndFunc

Func OtworzLink($sLink)
        _WD_Startup()
    $sSession = _WD_CreateSession($sDesiredCapabilities)
    _WD_Navigate($sSession, $sLink)
    _WD_LoadWait($sSession, 2000)
    EndFunc

When i change from $sFileRead to $sOgloszeniaReadOpen it doesn't paste at all, also _WD_SetElementValueNew doesn't paste with white spaces, it just  types '\r\n' on this one site

Link to comment
Share on other sites

@AnnoyingClown This isn't what I was requesting because --

  • it doesn't run 
  • it requires additional resources (an external file) that shouldn't be required for a simple reproducer

I did notice that you dropped the usage of , $_WD_OPTION_Advanced when you switched back to _WD_SetElementValue. Was this an oversight?

15 minutes ago, AnnoyingClown said:

When i change from $sFileRead to $sOgloszeniaReadOpen it doesn't paste at all, also _WD_SetElementValueNew doesn't paste with white spaces, it just  types '\r\n' on this one site

Not really sure what all that means. You may need to switch to using a different technique like updating the innerHTML or innerText property instead.

Link to comment
Share on other sites

@AnnoyingClown Got your PM. Here's a simplified version of your script that sets the body element's innerText property instead of using _WD_SetElementValue  --

#include "wd_core.au3"
#include "wd_helper.au3"
#include <String.au3>

Global $sElement, $sTestElement, $sSession, $sFilePath='1.txt', $sDesiredCapabilities

SetupGecko()
_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, 'https://justpaste.it/')
_WD_LoadWait($sSession, 2000)

Global $sFileRead = _StringRepeat("Test" & @CRLF, 10)
$sFileRead = StringReplace($sFileRead, @CRLF, '\r\n')

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='tinyMCEEditor_ifr']")
_WD_FrameEnter($sSession, $sElement)
$sTestElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//body[@id="tinymce"]')

$sScript = "arguments[0].innerText = arguments[1];"
$sJsonElement = '{"' & $_WD_ELEMENT_ID & '":"' & $sTestElement & '"}'
$sResult = _WD_ExecuteScript($sSession, $sScript, $sJsonElement & ',"' & $sFileRead & '"')

Func SetupGecko()
    _WD_Option('Driver', 'geckodriver.exe')
    _WD_Option('DriverParams', '--log trace')
    _WD_Option('Port', 4444)

    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts":true}}}'

EndFunc   ;==>SetupGecko

 

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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