Jump to content

Multiline String frome a txt file


Recommended Posts

Can you post example of your file and end result example you need, including script of your try @ it and url to where you need to paste it?

 

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

    Global Const $sFilePathWymagania = 'C:\Users\micha\Documents\1\wymagania.txt'
    Global Const $sFilePathOpis = 'C:\Users\micha\Documents\1\opis.txt'
    Global Const $sFilePathOgloszenie = 'C:\Users\micha\Documents\1\ogloszenie.txt'
    Global Const $sFilePathTytul = 'C:\Users\micha\Documents\1\tytul.txt'
    Global $sDesiredCapabilities, $sSession
    Global $sElement, $aElements, $sValue, $sButton, $sResponse, $bDecode, $hFileOpen

Func Wskaznik()
        $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sElementSelector)
    EndFunc

Func TytulReadOpen()
        Global $hFileOpen = FileOpen($sFilePathTytul, $FO_READ)
    Global $sFileRead = FileRead($hFileOpen)
    EndFunc
Func OgloszenieReadOpen()
        Global $hFileOpen = FileOpen($sFilePathOgloszenie, $FO_READ)
    Global $sFileRead = FileRead($hFileOpen)
    EndFunc
Func OpisReadOpen()
        Global $hFileOpen = FileOpen($sFilePathOpis, $FO_READ)
    Global $sFileRead = FileRead($hFileOpen)
    EndFunc
Func WymaganiaReadOpen()
        Global $hFileOpen = FileOpen($sFilePathWymagania, $FO_READ)
    Global $sFileRead = FileRead($hFileOpen)
    EndFunc


_WD_Startup()
    $sSession = _WD_CreateSession($sDesiredCapabilities)
    _WD_Navigate($sSession, "https://ofero.pl/dodaj")
    Wskaznik()
    $sElementSelector = "//input[@name='add_title']"
    TytulReadOpen()
    _WD_ElementAction($sSession, $sElement, 'value', $sFileRead)
    $sElementSelector = "//textarea[@name='add_description']"
    Wskaznik()
    OgloszenieReadOpen()
    _WD_ElementAction($sSession, $sElement, 'value', $sFileRead)
    $sElementSelector = "//select[@name='add_country']"
    Wskaznik()
    _WD_ElementAction($sSession, $sElement, 'value', "Polska")
        $sElementSelector = "//select[@name='add_region']"
    Wskaznik()
    Sleep(1000)
    _WD_ElementAction($sSession, $sElement, 'value', "mazowieckie")
    Sleep(1000)
    $sElementSelector = "//select[@name='add_location']"
    Wskaznik()
    _WD_ElementAction($sSession, $sElement, 'value', "Warszawa")
    _WD_Shutdown()

i need to paste a huge amount of text in a text bar 'add_description' but i cant paste more than one line of text, its only a part of my file if i forgot something, sorry

Link to comment
Share on other sites

This is more for someone that playes around with WebDriver   @Danp2 or others.

I never used WebDriver  so i realy im not gona b of help heare. Im tapping out.

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

FWIW, here's an example that works for me. Perhaps it will help you figure out your issue --

#include "wd_core.au3"
#include "wd_helper.au3"

Local $sDesiredCapabilities, $sSession
Local $sElement, $sText = '1234' & @CRLF & '5678' & @CRLF & '90' & @CRLF

SetupChrome()
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)

_WD_Navigate($sSession, "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_textarea")
_WD_LoadWait($sSession, 2000)

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iframe[@id='iframeResult']")
_WD_FrameEnter($sSession, $sElement)

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//textarea[@id='w3review']")
_WD_ElementAction($sSession, $sElement, 'clear')
_WD_ElementAction($sSession, $sElement, 'value', $sText)


Func SetupChrome()
    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')

    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false, "prefs": {"credentials_enable_service": false, "profile.password_manager_enabled": false}}}}}'
EndFunc

 

Link to comment
Share on other sites

And sorry i just relizzed how to quote people

8 minutes ago, AnnoyingClown said:

Well it pastes, but all in one line, and i want to paste it with @CRLF

that was to @JockoDundee

1 minute ago, AnnoyingClown said:

I want to make it so i can edit txt file and it just pastes whats in that file, without needing to manualy add something like this 


$sText = '1234' & @CRLF & '5678' & @CRLF & '90' & @CRLF

and that to Danp2

Link to comment
Share on other sites

1 minute ago, Danp2 said:

If ogloszenie.txt contains a single line of text, then that is what will get inserted into the element. If you need something different, then you will need edit the data prior to submitting it via the webdriver.

i need to paste text like this, what do you mean by editing the data prior to submitting?

Screenshot_75.png.e16c32b7081cc4681d76e58114b9c5df.png

Link to comment
Share on other sites

36 minutes ago, Danp2 said:

What type of line terminator is being used (ie: CR, CRLF or LF)? Maybe you need to change it with something like StringAddCR.

i don't really know anything about terminators, the text is taken from siple txt file, and if i need to check something on website, pls tell me how.
doesnt StringAddCR just adds something at the beggining of each line? or im getting it wrong?

Link to comment
Share on other sites

8 minutes ago, AnnoyingClown said:

i don't really know anything about terminators, the text is taken from simple txt file

A fairly simple way would be to open the text with Notepad++. Depending on the version you should find an option like :

View->Show Symbol->Show All Characters

or

View->Show Symbol->Show White Space and Tab

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

@Danp2 Sorry for wasting your time before, now i think i know what is the problem.
 

On 5/5/2021 at 4:36 PM, Danp2 said:

FWIW, here's an example that works for me. Perhaps it will help you figure out your issue --

#include "wd_core.au3"
#include "wd_helper.au3"

Local $sDesiredCapabilities, $sSession
Local $sElement, $sText = '1234' & @CRLF & '5678' & @CRLF & '90' & @CRLF

SetupChrome()
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)

_WD_Navigate($sSession, "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_textarea")
_WD_LoadWait($sSession, 2000)

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iframe[@id='iframeResult']")
_WD_FrameEnter($sSession, $sElement)

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//textarea[@id='w3review']")
_WD_ElementAction($sSession, $sElement, 'clear')
_WD_ElementAction($sSession, $sElement, 'value', $sText)


Func SetupChrome()
    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')

    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false, "prefs": {"credentials_enable_service": false, "profile.password_manager_enabled": false}}}}}'
EndFunc

 

in this code you have told me that its working just fine, i have assumed that its just right and it would work for me also but it does not work with geckodriver(firefox), so idk if its possible with it anymore
 

 

On 5/5/2021 at 5:56 PM, Danp2 said:

What type of line terminator is being used (ie: CR, CRLF or LF)? Maybe you need to change it with something like StringAddCR.

CRLF is used, thanks for help with that @Musashi xd

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...