2

I need to replace a portion of following url in selenium webdriver+python:

https://ve-215:8443/cloudweb/dropbox_authorized?oauth_token=l8eYuFG8nux3TUHm&uid=69768040

I need to replace ve-215 to a ip address say 192.168.24.53

I tried using replace but it doesnt work.

Following is code I am using:

current_url=driver.current_url
print(current_url) #prints the url of the current window.

current_url.replace("ve-215", "192.168.53.116")
print(current_url)  #print url with replaced string
driver.get(current_url) #open window with replaced url

Can anyone help me with what is wrong with the above code?

2 Answers 2

3

replace method does not modify the string itself (strings are immutable in Python) but returns a new string. Try

current_url = current_url.replace("ve-215", "192.168.53.116")

That being said, it is advised to use urlparse module (urllib.parse in Python 3) for parsing and reconstructing URLs.

Sign up to request clarification or add additional context in comments.

Comments

2

The replace method returns a string with the modifications applied but does not modify the current string.

You should use it that way :

current_url = driver.current_url
print(current_url) #prints the url of the current window.

current_url = current_url.replace("ve-215", "192.168.53.116")
print(current_url)  #print url with replaced string
driver.get(current_url) #open window with replaced url

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.