1

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.

Sparkflight
  • 51
  • 1
  • 9
  • what is the output of your script above? how is it "not working"? – Breaks Software Mar 21 '18 at 23:26
  • There is no output, it just hangs indefinitely until end the program. – Sparkflight Mar 21 '18 at 23:58
  • and has it navigated to the target web page? – Breaks Software Mar 22 '18 at 00:04
  • Yeah, it opens the url I put just fine, but hangs forever on `driver.get(vid)` – Sparkflight Mar 22 '18 at 00:08
  • well, then there is no problem with the driver.current_url, it never gets that far. the problem is with the path you have in the variable "vid". can you open that in the same browser manually? – Breaks Software Mar 22 '18 at 00:14
  • It does, seems that the issue is selenium grabbing the url after the page has changed, as after I removed the loaded extension it grabbed the page url. However I've read that current_url is dynamic and will just grab the current page regardless so I'm lost why its not working. – Sparkflight Mar 22 '18 at 00:35

1 Answers1

1

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

PixelEinstein
  • 1,713
  • 1
  • 8
  • 17
  • I've done this and same result, added a comment with the results. – Sparkflight Mar 22 '18 at 00:35
  • So, it's getting passed the `.get()` now? – PixelEinstein Mar 22 '18 at 00:37
  • No, its not returning the pages url after it changes. If I disable the extension that changes the pages url it works, but when the extension is enabled it returns to not working. Which would be ok except I am under the impression that it should return the url of the page at the current instance. – Sparkflight Mar 22 '18 at 00:41
  • by *"return the url"*, you mean it should progress passed the `.get()`? Or are you actually getting to the `current_url`? If you are still hanging on `.get()`, is the page loading or does it seem to load forever? Check circle in top left. – PixelEinstein Mar 22 '18 at 16:25