why do i need to use this code to get the text value from the x path
from selenium import webdriverfrom selenium.webdriver.common.by import Byimport timewith open('restaurants.csv', 'w', encoding='utf-8') as file: file.write('name \n')driver = webdriver.Chrome()driver.get('https://www.tripadvisor.co.nz/Restaurants-g1811027-Auckland_North_Island.html')time.sleep(3)names = driver.find_elements(By.XPATH, "//div[@class='biGQs _P fiohW alXOW NwcxK GzNcM ytVPx UTQMg RnEEZ ngXxk']/a")with open('restaurants.csv', 'a', encoding='utf-8') as file: for name in names: file.write(name.text +'\n')file.closedriver.quit()
but when i used my original code it would not allow me to get the text value from the xpath why?
from selenium import webdriverfrom selenium.webdriver.common.by import Byimport timewith open('restaurants.csv', 'w', encoding='utf-8') as file: file.write('name \n')driver = webdriver.Chrome()driver.get('https://www.tripadvisor.co.nz/Restaurants-g1811027-Auckland_North_Island.html')time.sleep(3)name = driver.find_elements(By.XPATH,"//div[@class='biGQs _P fiohW alXOW NwcxK GzNcM ytVPx UTQMg RnEEZ ngXxk']/a")with open('restaurants.csv', 'a', encoding='utf-8') as file: for i in range(len(name)): file.write(name.text +'\n')file.closedriver.quit
thanks :)