Home > OS >  PYTHON SELENIUM :Is there a way to copy the text from a List<WebElement> into an other List(st
PYTHON SELENIUM :Is there a way to copy the text from a List<WebElement> into an other List(st

Time:01-03

Hi i m not familiar with stack overflow, i would like some help to solve this problem: I manage to get a list of webElements with their xpath and my end goal is to search paste each one of them (1 at the time) in the google search bar. My idea was to copy the List(webElements) to an other List so that i can store those(string)values and 1 at the time search for them. the code look like this:

nome = wd.find_elements_by_xpath('/html/body/div[2]/div/div[3]/div/div/div[2]/div/ul/li')
elements=[]
for i in range(0,40):
     nome[i].text=elements[i]
wd.get('https://google.com')
#accepts cookies wd.find_element_by_xpath('/html/body/div[2]/div[2]/div[3]/span/div/div/div/div[3]/button[2]/div').click()
for i in range(0,40):
wd.get('https://google.com')
wd.find_element_by_xpath('/html/body/div[1]/div[3]/form/div[1]/div[1]/div[1]/div[2]/div[2]/input').send_keys(elements[i])

CodePudding user response:

elements=[elem.text for elem in none]

Is what you are trying to do. Go through each element in none and grab the .text.

CodePudding user response:

To copy the text from the WebElements into another list you can use List Interpolation as follows:

nome_texts = [my_elem.text for my_elem in wd.find_elements_by_xpath('/html/body/div[2]/div/div[3]/div/div/div[2]/div/ul/li')]
  • Related