AnnoyingClown Posted May 5, 2021 Share Posted May 5, 2021 I would like to create a multiline string from saved txt file, is it possible? Link to comment Share on other sites More sharing options...
matwachich Posted May 5, 2021 Share Posted May 5, 2021 FileRead("file.txt") ? Link to comment Share on other sites More sharing options...
AnnoyingClown Posted May 5, 2021 Author Share Posted May 5, 2021 I use file read but, when i try to paste from it in to a web site, it does not work if it has more than one line of text. Link to comment Share on other sites More sharing options...
bogQ Posted May 5, 2021 Share Posted May 5, 2021 (edited) 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 May 5, 2021 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) 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 More sharing options...
AnnoyingClown Posted May 5, 2021 Author Share Posted May 5, 2021 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 More sharing options...
bogQ Posted May 5, 2021 Share Posted May 5, 2021 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 connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) 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 More sharing options...
JockoDundee Posted May 5, 2021 Share Posted May 5, 2021 2 hours ago, AnnoyingClown said: 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 Will it work if you replace the newlines: $sFileRead = FileRead($hFileOpen) $sFileRead = StringReplace($sFileRead, @CRLF, " ") Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Danp2 Posted May 5, 2021 Share Posted May 5, 2021 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 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
AnnoyingClown Posted May 5, 2021 Author Share Posted May 5, 2021 Well it pastes, but all in one line, and i want to paste it with @CRLF Link to comment Share on other sites More sharing options...
AnnoyingClown Posted May 5, 2021 Author Share Posted May 5, 2021 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 Link to comment Share on other sites More sharing options...
AnnoyingClown Posted May 5, 2021 Author Share Posted May 5, 2021 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 More sharing options...
Danp2 Posted May 5, 2021 Share Posted May 5, 2021 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. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
AnnoyingClown Posted May 5, 2021 Author Share Posted May 5, 2021 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? Link to comment Share on other sites More sharing options...
AnnoyingClown Posted May 5, 2021 Author Share Posted May 5, 2021 The only way i see it for now to make it work is to make it replace @CRLF to something like Q and then manualy adding @CRLF on site, i hope that there is a better solution 😧 Link to comment Share on other sites More sharing options...
Danp2 Posted May 5, 2021 Share Posted May 5, 2021 What type of line terminator is being used (ie: CR, CRLF or LF)? Maybe you need to change it with something like StringAddCR. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
JockoDundee Posted May 5, 2021 Share Posted May 5, 2021 37 minutes ago, Danp2 said: Maybe you need to change it with something like StringAddCR. Or maybe change the CRLF to just LF. Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
AnnoyingClown Posted May 5, 2021 Author Share Posted May 5, 2021 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 More sharing options...
Danp2 Posted May 5, 2021 Share Posted May 5, 2021 @AnnoyingClown There's this thing that comes with AutoIt called a "help file". Suggest that you use it to answer your own question. 🙄 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Musashi Posted May 5, 2021 Share Posted May 5, 2021 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 "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 More sharing options...
AnnoyingClown Posted May 7, 2021 Author Share Posted May 7, 2021 @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 More sharing options...
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