In selenium, I am grabbing some search result URL by XPATH. Now I want to click then one by one which will open then in the same browser one by one where the base URL is opened so that I can switch between then. How can I do that? I am giving my code below.
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
serv_obj = Service("F:\Softwares\Selenium WebDrivers\chromedriver.exe")
driver = webdriver.Chrome(service=serv_obj)
driver.maximize_window()
driver.implicitly_wait(5)
url = "https://testautomationpractice.blogspot.com/"
driver.get(url)
driver.find_element(By.XPATH, "//input[@id='Wikipedia1_wikipedia-search-input']").send_keys("selenium")
driver.find_element(By.XPATH, "//input[@type='submit']").click()
search_result = driver.find_elements(By.XPATH, "//div[@id='wikipedia-search-result-link']/a")
links = []
for item in search_result:
url_data = item.get_attribute("href")
links.append(url_data)
print(url_data)
print(len(links))
print(links)
I have grabbed all the links from the search result by using customized XPATH. I am being able yo print them also. But I want to open/click on the every resulted link one by one in the same browser.