Skip to content Skip to sidebar Skip to footer

Selenium In Python - Running Javascript

I'm trying to scrape a website that is mainly ran by javascript and it's giving me a huge headache because I don't know javascript. This is what I have so far: from selenium impo

Solution 1:

driver.findElement is Selenium syntax, while inside driver.execute_script you need JavaScript syntax:

driver.execute_script("some javascript code comes here");

To find the right function, look at document DOM object: just like document.getElementById, which you previously used, it has document.getElementsByName() function. Note that unlike ID, that can return 1 element only, there can be many elements with the same name, hence function returns them all as an array. So your statement becomes:

driver.execute_script("document.getElementsByName('estimated-monthly-usage')[0].value='1000'");

Post a Comment for "Selenium In Python - Running Javascript"