0

First, sorry for the confusing title-question. I am currently migrating a browser automated project from iMacros to Selenium-Python. For my previous iMacros scripts, I have been using a javascript function to open url's since it is a lot faster. Here's a code to test the immense difference in loading speeds:

SET !FOLDER_STOPWATCH C:\Users\Public\Documents
SET !FILESTOPWATCH "Duration.txt"

STOPWATCH ID=Javascriptey_mode
URL GOTO=javascript:window.open("http://cityplan2014maps.brisbane.qld.gov.au/CityPlan/");
STOPWATCH ID=Javascriptey_mode

STOPWATCH ID=Regular_mode
TAB OPEN
TAB T=3
URL GOTO="http://cityplan2014maps.brisbane.qld.gov.au/CityPlan/"
STOPWATCH ID=Regular_mode

Unfortunately I have no idea why this happens and I'm under the assumption that being able to open a URL in Selenium using a similar javascript method will hasten page loading. Selenium's driver.get(url) command does not cut it for me. I tried using Firefox profiles to no avail. So how do I go about it using this? I'm open for a non-javascript-ey solution, too. Also, if anyone could explain to me why the regular iMacros URL GOTO=(url) command loads slowly compared to the Javascript-ey one, it would be much appreciated :)

This might not be of value but here are the versions I'm using with iMacros:

  • Firefox 55.0.3
  • iMacros Addon version 9.0.3

EDIT: Updated the iMacros code to allow for time duration monitoring. I ran it three times on my end and saw an average difference of 43 seconds between the regular and Javascript-ey mode.

4
  • 1
    Try driver.execute_script('window.open("http://cityplan2014maps.brisbane.qld.gov.au/CityPlan/");') Commented Jan 17, 2019 at 10:51
  • Hi @andersson. Thanks for the suggestion. The command runs but it still takes forever to load :( Commented Jan 17, 2019 at 11:12
  • I don't know what you are seeing but there shouldn't be any difference in opening the browser using Selenium and setting the URL and opening a tab with a URL. I bet if you ran each test 100 times, the average speed would be the same. Commented Jan 17, 2019 at 13:57
  • @JeffC : The difference is very huge, like 43 seconds huge :|. I will update the iMacros code above to add time duration checking. It would really be helpful if someone could run it on their end to help me see if there is something I'm missing here Commented Jan 19, 2019 at 1:09

1 Answer 1

2

You can execute your js code this way:

driver = webdriver.Chrome()
driver.get("http://google.com")
driver.execute_script("window.open('http://cityplan2014maps.brisbane.qld.gov.au/CityPlan/')")
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for this suggestion :). I failed to point out that I prefer to work with Firefox for this one. But I did try your fix using chromedriver and the problem persisted i.e. the loading time did not improve,.
The actual question was ... why the regular iMacros URL GOTO=(url) command loads slowly compared to the Selenium/Javascript...
@DebanjanB No, the actual question is in the title... "How to open URL in Selenium via Python using Javascript functions" and this is a plausible answer to the question.
I get: TypeError: webdriver.Chrome is not a function
@bigEvilBanana : I just came back to this project and happy to say that this is working! Not sure what happened when I tested it the last time . Cheers!

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.