3
I’m creating a bot that searches a word in google and writes in a txt file all links found in the search
I am currently trying to find a keyword on the search result page, store the links that contain that keyword in a variable and write to txt:
string mencoesDaPalavra = Driver.FindElements(By.PartialLinkText("Palavra a pesquisar")).ToString();
After "capturing" the links that contain the word I’m trying to write to the file like this :
StreamWriter file = new StreamWriter("new.txt");
file.Write(mencoesDaPalavra);
file.Close();
My attempt was unsuccessful, the line recorded in the file does not match what I am searching for.. as I could do ?
line saved in file :
new.txt = "System.Collections.ObjectModel.ReadOnlyCollection`1[OpenQA.Selenium.IWebElement]"
The method
FindElements
returns an array of objects (Webelement) and not a string. You need to iterate on this array to get links.– Pagotti