I am trying to open URL found based on link_text in a loop. The below is the program that I am trying to use.
Actually, what happening, actually on that page I have details 3 times, some times it will be 4 times (it's dynamic).
Updated Code:
from selenium.webdriver.support import ui
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import NoSuchElementException
from selenium import webdriver
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(chrome_options=options, executable_path='C:\chromedriver_win32\chromedriver.exe')
driver.maximize_window()
driver.get("https://xxxxxx/blogs/")
if driver.find_element_by_xpath("(//span[@class='ui-datepicker-month'][contains(.,'May')])[1]"):
# get the number of details to click
addr = driver.find_elements_by_link_text('Details')
urls = [v.get_attribute("href") for v in addr]
for x in range(1, len(urls) + 1):
driver.execute_script("window.open();")
driver.switch_to.window(driver.window_handles[x])
driver.get(urls[x - 1])`
Output is:
Its working correctly, open all detail href in new tabs.
Update 2:
As per Dmitri T code, now its working opening all details href in new tabs :) thanks for help. One final I would like to try is in datepicker loop, i have hardcoded the date as //span[@class='ui-datepicker-month'][contains(.,'May')])[1]" in may month. How can i loop through this i.e to click on each day means. click on 1st may,open all "details" href in each newtab,go to main url again, click on 2nd May, do the same stuff...open all "details" href in new tabs...so on..I am trying to write code...let you know results. thanks you experts.