Get text from a prompt alert using python selenium webdriver

I'm trying to scrape this page: The problem I have is how to get the number to the left of the copy to clipboard button below the avatar (0x068C...). When I'm using python selenium webdriver with Chrome, instead of copying the number to the clipboard, the browser shows a prompt alert that says Copy to clipboard: Ctrl+C, Enter and shows a textbox with the number I need.

I cannot inspect the code of the alert to catch the element. I've tried using

alert = driver.switch_to.alert
alert.send_keys(Keys.CONTROL, 'c')

But it gives me

TypeError: send_keys() takes 2 positional arguments but 3 were given

I've also tried using a JS script

driver.execute_script("""arguments[0].getAttribute("value");""", alert)

but it looks like I cannot send the alert element as an argument

TypeError: Object of type Alert is not JSON serializable

Read more here:

Content Attribution

This content was originally published by ABraslavskiy at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: