Execute Javascript using Selenium Python - Part 13
ฝัง
- เผยแพร่เมื่อ 20 ต.ค. 2024
- In this video, I have explained how to execute javascript code using selenium python.
It may so happen in some real time projects, Selenium WebDriver is not able to perform some action on a particular web element and interacting with web elements through Javascript was the only possible solution.
~~~~Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:
www.youtube.co...
Follow me on my Facebook Page:
/ naveenqtpexpert
Let's join our Automation community for some amazing knowledge sharing and group discussion on Telegram:
t.me/joinchat/...
Paid courses (Recorded) videos:
naveenautomati...
For Java & Selenium - naveenautomatio...
For API (Manual + Automation) - naveenautomatio...
Very well explained , Helpful..Thank you
Excellent job done by Naveen Sir , the master of Automation
Good Job Naveen
Hi Naveen How click on ag-grid table can you please explain
hi, this video was greatly helpful. but is there a way to click on a video and scroll through the video using execute_script? or something in selenium?
Hello Naveen!
Thanks a lot for your job.
Will you explain on moving to the top of the page - why did you put window height on x-coordinate? I belive that (0, 0) coordinates will work. Am I wrong here?
Yes you can put 0,0 also
Hey Naveen, is this also an important topic in JS executor- executeAsyncScript?
Naveen it was working for me if I am using print and putting the driver part in it
Hi Naveen,
The sendKeys with JavaScriptExecutor is working as below. I have tried the same on the hubspot application.
username=driver.find_element(By.ID,'username')
driver.execute_script("arguments[0].value='amol.nawale';",username)
Thanks for the answer!! How can i pass the value dynamically?
For dynamically
driver.execute_script("document.getelementbyid("idbusca").value=" + (dynamically))
some sites says access denied when refresh by history.go(0) also some scripts don't work. Any solution for that?
Do you know why scrollTo is not working in browser console and python. I tested in browser with different data window.scrollTo(0,800); and changed the 800 to other number and still it did nothing. Python not scrolling as well. Tested in chrome
def scroll(self, down=0): # it will go down and up according to your choice 1 or by default 0 value
"""This method will be used to scroll up and down to any page"""
self.driver.find_element_by_tag_name('html').send_keys(Keys.END)
if down == 1:
print("")
time.sleep(3)
else:
time.sleep(5)
self.driver.find_element_by_tag_name('html').send_keys(Keys.HOME)
# self.driver.execute_script("window.scrollTo(0,500)")
now the command to scroll down a yourtube page is:
driver.execute_script("window.scrollTo(0, document.documentElement.scrollHeight)")
Hi Naveen. Can you please demo how to handle a calendar using with the help of selenium and Javascript using Python?
Awaiting your response.
Thanks in advance!
Haii Bharat Kumar,
Can u give hint about this, I have to pic date in calendar using python
Hi Naveen, I can't able to join ur telegram group...
Hello Naveen,
Thanks for explaining the JS method.
I tried it on the same application for send value to the textbox.
email = driver.find_element(By.ID, 'username')
driver.execute_script("document.getElementById('username').value='rahul_pawar', email;")
# Selenium data sending
driver.find_element(By.ID, "ta1").send_keys("Sigma Male")
# Javascript data sending
text_box_field = driver.find_element(By.ID, "ta1")
driver.execute_script("arguments[0].value='Sigma Male'", text_box_field)
Can anyone suggest how to input text/value using javascript in Robot framework?
I have tried this, but not working.
Execute Javascript arguments[0].value='123'; xpath
Hi Naveen,
Thank you for the tutorials, getting to learn a lot from these.
Can you please add a tutorial to handle date picker/calendar as it is a very important use case these days?
Haii chakradhar reddy,
Can u give hint about this, I have to pic date in calendar using python
driver.get("seleniumpractise.blogspot.com/2016/08/how-to-handle-calendar-in-selenium.html")
# Javascript code
calender_field = driver.find_element(By.ID, "datepicker")
driver.execute_script("arguments[0].value='04/12/2024'", calender_field)
Hi Naveen
Please make videos on nightwatch as well.🙏
Thank you in advance 😊