Reputation: 31985
I'm looking for a way to type in strings in the browser URL bar without sending the return key. I just want to show the strings there because there is no other place to add my own string descriptions to the window.
However, I could not find any way to locate the address bar and type in something. The only way to get something about the address bar is driver's current_url attribute, but it just returns the current URL.
Is it possible to get the address bar and type in something on Selenium?
I use Chrome driver and the versions are Python 3.7 and Selenium 3.141.0 on macOS Mojave.
The reason I want to show it is because I must choose and save an image on the browser window, but at the same time I need my description to choose which image to save. It is very tedious to go to Terminal output and read the description and then go back to the browser to choose the image, and that's why I want to show it on the address bar.
Upvotes: 3
Views: 5523
Reputation: 1354
You could use driver.get and add a bookmark for your note....
driver.get("https://yourwebsite.com/yourwebpage.htm#" + yournote)
You could also execute a javascript to change the page's title, or add a div along the top of the page.
Upvotes: 0
Reputation: 36
There Is No Way To Type Into The Search Bar Without Importing Another Library But If You Want To Search For Something You Can Use driver.get("https://www.google.com/search?q="+Search Query)
Example:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.google.com/search?q="+SEARCH QUERY)
Upvotes: 1
Reputation: 16172
You can use the built into functionality of python to achieve this. Here's a list of the sendkeys commands you can use:
import win32com.client as comctl
w = comctl.Dispatch('WScript.Shell')
# Switch to Chrome
w.activate('Chrome')
# Crl+L to activate address bar
w.sendkeys('^l')
w.sendkeys('whatever string you want to show up in address bar here')
Upvotes: 0