0

Trying to make Driver.get() work for multiple different URL's but that seems to be impossible as .get has to contain a string , it can not contain a variable that is a string and neither can you convert it to a string in the process.

driver1 = webdriver.Chrome()
TradeURL1 = "https://app.libertex.com/products/crypto/Bitcoin/" #User stated
#driver1.execute_script(driver1.get(str(TradeURL1)))
driver1.get(TradeURL1)#https://app.libertex.com/products/metal/XAUUSD

declaring the URL as a variable and placing the variable name in the .get throws the script must be a string error .

selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: 'script' must be a string
  

but placing the URL in like this

driver1.get("https://app.libertex.com/products/metal/XAUUSD")

works perfectly fine . how are you supposed to make your code versatile and adapt it if you cant place a variable name there(the URL is changing throughout the code) Is there a way around this other than using multiple drivers (because i will not even know how many drivers i will be using + using multiple drivers takes more processing power and is inefficient)

similar question enter link description here

edit after @DeepSpace

driver1 = webdriver.Chrome()
TradeURL1 = "https://app.libertex.com/products/crypto/Bitcoin/" #User stated
#driver1.execute_script(driver1.get(str(TradeURL1)))
driver1.get(TradeURL1)#https://app.libertex.com/products/metal/XAUUSD
time.sleep(5)
driver1 = login()

the driver1 = login() login() is a subroutine i have built, when i run the code(works for when you actually put a string in get) it works fine. But when running with driver1.get(TradeURL1) shows this error

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"#login-field"}

backtracking what i had done up to that point ..changing driver1.get("Actual string") to driver1.get(TradeURL1) and sure enough the issue was the script must be a string error ... im confusedas you are @DeepSpace

Hamza Arshad
  • 121
  • 1
  • 3
  • 11
  • I doubt this is actually what's going on. Provide full [mcve] + stacktrace – DeepSpace Aug 15 '20 at 21:37
  • yes i was amazed and confused aswell – Hamza Arshad Aug 15 '20 at 21:44
  • `.get` has virtually no way to detect if it was given a variable or a string literal, hence I asked for a **reproducible** example including the full stacktrace. As of now, this is not reproducible – DeepSpace Aug 15 '20 at 21:47
  • After your edit: please take a step back. The error you now show us is completely different than the original error. Take the time to understand exactly what causes which error. – DeepSpace Aug 15 '20 at 21:52
  • No im saying that the second error i showed only exists because of the first one.My code worked fine until i placed TradeURL in the get() – Hamza Arshad Aug 15 '20 at 21:53
  • You were saying that get() has no way of knowing if it has a litereal or a variable. Could you explain this? – Hamza Arshad Aug 15 '20 at 21:55

0 Answers0