I have a script written in python that open a web page in chrome, does some pre-processing on that page and than I need to run a java script code on that web page(manually it can be done using press F12 in chrome and copy to the console), but is there any library that can automate this for me? I mean some command in Python that will run the JS code directly on the opened chrome page(after all the pre-process done on it)?
Asked
Active
Viewed 158 times
1 Answers
1
Not sure exactly what library/package you are using, but this can be achieved using Selenium, specifically the execute_script
function.
This approach is discussed in more detail in this SO question.

Anis R.
- 6,656
- 2
- 15
- 37
-
Hi! I am using first pyautogui in order to do some manipluation on the webpage and then I need to run the script on that page after all the process, as I see in that link I won't be able to combine the two, because I need all the pre processing to be done in Selenium and unfortunately this is impossible, Is there any way to run the script after process the webpage with pyautogui? – user2207686 Aug 25 '20 at 13:50
-
@user2207686 Not a pyautogui expert, but I'd assume you could use it to hit f12 (launch dev tools), then click on input in console and paste the JS code there. Hope this makes some sense. I'd recommend doing the whole thing in Selenium though if possible, as it makes it so much easier to locate DOM elements (by id/selector instead of pixels) and interact with them. – Anis R. Aug 25 '20 at 14:34