hellojoshhhy
hellojoshhhy

Reputation: 958

Python selenium send_keys() escape forward slash in URL

I trying to send a URL with Selenium send_keys(url) For example, the URL parsed to the script is https://www.test.com/downloads/myfile.zip

URL sent by selenium to my application then become https:www.test.comdownloadsmyfile.zip

i tried url.replace('/', '\/') and url.replace('/', '\\/'), but still not getting the correct URL.

Upvotes: 3

Views: 939

Answers (1)

RichEdwards
RichEdwards

Reputation: 3743

send_keys works fine with forward slashes - chances are this is specific to your application or your input data.

This is some sample code as a demo:

driver = webdriver.Chrome() # note i modified this to my driver
driver.implicitly_wait(10)

url = "https://www.duckduckgo.co.uk"
driver.get(url)
driver.find_element(By.ID, "search_form_input_homepage").send_keys(url)

This is what you see - complete with forward slashes:

duck with slash

###########################

An alternative way to set a value is to use JS. Try this approach:

url = "https://www.duckduckgo.co.uk" 
driver.get(url)
element= driver.find_element(By.ID, "search_form_input_homepage")#.send_keys(url)
driver.execute_script("arguments[0].value=arguments[1]", element, url)

If the above samples work for you on duckduckgo - that suggest it's your application or your data, and not your machine/selenium/version.

What you can try next is to rule out your input data and find the boundaries of the issue. Try a hard coded .send_keys('/').

  • If that works, you know its your input data.
  • If that fails, you know it's your application

Try a print on your data.

  • If that has salshes after it's parsed into your test, it's something else

Beyond that - please share more code and more information around the issue.

Upvotes: 0

Related Questions