Sparkflight
Sparkflight

Reputation: 51

Getting current page url with selenium

I'm using selenium to open a page. I'm trying to get the current opened page url but I can't seem to get it.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import getpass

vid = 'https://openload.co/f/KgNvMOs9fws/C__Program_Files_Python36_placeholder.mp4'
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('load-extension=C:/Users/'+getpass.getuser()+'/AppData/Local/Google/Chrome/User Data/Default/Extensions/leallakffbiflfgpmamdgcojddnbfdgo/1.1.8_0')
driver = webdriver.Chrome(chrome_options=chrome_options)
print('Start')
driver.get(vid)
print('Middle')
urlpage = driver.current_url
print(urlpage)
print('End')

I have a chrome extension that modifies the url of the video. I'm trying to grab that modified page url, but there is no point in adding a time delay since I can't grab the url of the video page in the first place for some reason. And driver.current_url is not working.

Upvotes: 1

Views: 2472

Answers (1)

PixelEinstein
PixelEinstein

Reputation: 1723

If you are having issues with .get(), then you must be on a bad combination of chromedriver and Chrome browser.

I would recommend updating to chromedriver 2.36 or Above from HERE

And also make sure you have updated to the current Chrome Build 65 by opening this URL:

chrome://settings/help

If you cannot update to current, please try this:

from selenium import webdriver

ChromeOptions = webdriver.ChromeOptions()
ChromeOptions.add_argument('--disable-browser-side-navigation')
driver = webdriver.Chrome('your/path/to/chromedriver.exe', chrome_options=ChromeOptions)

For my original answer on this issue, please refer to THIS

Upvotes: 1

Related Questions