Python, Selenium возможно ли получить новую ссылку от скрипта
Суть скрипта в том что он запрашивает ссылку, далее переходит по ней, выполняет несколько действий и переходит на новую ссылку. Можно ли сделать так чтобы скрипт отправлял последнюю ссылку пользователю? Я осмотрел документацию selenium`а но ничего не нашёл.
import time
import random
import string
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get(input("link here"))
driver.implicitly_wait(5)
search_box = driver.find_element(By.NAME, "SessionForm[firstname]")
search_button = driver.find_element(By.TAG_NAME, 'button')
def generate_random_string(length):
letters = string.ascii_lowercase
rand_string = ''.join(random.choice(letters) for i in range(length))
search_box.send_keys(rand_string)
generate_random_string(8)
search_button.click()
time.sleep(5)
search_button = driver.find_element(By.XPATH, '/html/body/div[1]/div/div/div/div/div/div[2]/div[2]/div/div[1]/div/div/p')
search_button.click()
time.sleep(5)
search_button = driver.find_element(By.CLASS_NAME, 'endSessionButton')
search_button.click()
Ответы (1 шт):
Автор решения: gil9red
→ Ссылка
Для получения текущей ссылки из selenium используйте свойство current_url:
...
print(driver.current_url)