4

I'm facing some difficulties while trying to get the content of 'Network' tab in Chrome Devtools using a python script. The script should use Selenium library in order to perform this action. I was wondering if this is possible, and if so, how would you do that? I've read some suggested solutions but none of them worked for me.

chrome_path = r"C:\Python27\chromedriver_win32/chromedriver.exe"
chrome_options = Options()  
chrome_options.add_argument("--headless")  
chrome_options.add_argument("window-size=1200,1100")


driver = webdriver.Chrome(executable_path=chrome_path,chrome_options=chrome_options)
driver.get("https://www.container.io/login")


elementUser = driver.find_element_by_id('username')
elementPassword = driver.find_element_by_id('password')
elementUser.send_keys(user)
elementPassword.send_keys(password)

What I want to capture on Network tab is :

Query String Parameters
   access_token: XXXXXXXXX
   evnId: XxxXXx
   sortBy: xxXXxx
user3819295
  • 861
  • 6
  • 19
  • What exactly do you want to capture? Do you want to capture network traffic? – markwalker_ Mar 25 '18 at 15:32
  • I want to capture the access token after I log into the website. It appears on the Network tab, in one of the GET methods – user3819295 Mar 25 '18 at 15:40
  • 2
    Network Traffic can not be selected using selenium, because no selector exists for Devtools window. Is it saved as a cookie? Sounds like it was sent via a response from server (for a GET request), so for you to use it for authentication for another GET, it has to be stored. You can access cookies using `driver.get_cookies()`. However if not, then I'm afraid the last thing you could try is see the response from server and take it apart. But Parsing Response is not possible in Selenium, as @JimEvans from the core team replies here https://stackoverflow.com/a/6512785/2453382 –  Mar 25 '18 at 16:16
  • Cookies might be a good idea, I'll check it now. – user3819295 Mar 25 '18 at 16:37

1 Answers1

0

https://stackoverflow.com/a/68363046/8491363

I actually stumbled upon a similar problem and posted an answer to an also similar question.

You have to use driver.get_log('performance') for this.

Check out the answer link above for details.

user8491363
  • 2,924
  • 5
  • 19
  • 28