2

i was trying to open link in a new tab. and the method i uses is like below.

driver.execute_script('''window.open("https://www.tracksellers.com/sellers/","_blank");''')

the above code works but i want to add some variable into it to construct full url like this below.

https://www.tracksellers.com/sellers/us/A294P4X9EWVXLJ/ankerdirect

this is what i have tried so far

driver.execute_script('''window.open("https://www.tracksellers.com/sellers/`{country}`/`{id}`","_blank");''')

but when it opened it adds other things, which gives me the output as below.

https://www.tracksellers.com/sellers/%60%7Bcountry%7D%60/%60%7Bid%7D%60

it is adding %60%7Bcountry%7D%60/%60%7Bid%7D%60 after https://www.tracksellers.com/sellers

1 Answer 1

2

You can parse the string like below :

I have taken num string and name string and parsing with %s

see the below code :

driver.get("https://www.tracksellers.com/")
num = "A294P4X9EWVXLJ"
name = "ankerdirect"
new_url = 'https://www.tracksellers.com/sellers/us/%s/%s/'  % (num, name)
driver.execute_script(f'''window.open("{new_url}","_blank");''')
Sign up to request clarification or add additional context in comments.

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.