Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions jsExecutor/example1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# import the webdriver
import time

from selenium import webdriver
from selenium.webdriver.common.by import By

options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=options)
driver.maximize_window()
# get method to launch the URL
driver.get("https://the-internet.herokuapp.com/inputs")
# to enter text in edit box
tb = driver.find_element(By.XPATH,"//input[@type='number']")
tb.send_keys("1234")
#print(tb.text)
time.sleep(5)
# extract the value with Javascript Executor
print(driver.execute_script('document.getElementsByTagName("input")[0].valueAsNumber'))
15 changes: 15 additions & 0 deletions jsExecutor/example2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# import the webdriver
import time

from selenium import webdriver
from selenium.webdriver.common.by import By

options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=options)
driver.maximize_window()
# get method to launch the URL
driver.get("https://the-internet.herokuapp.com/upload")
# to click on button with Javascript executor
btn = driver.find_element(By.ID,"file-submit")
driver.execute_script("arguments[0].click();",btn)
time.sleep(3)
15 changes: 15 additions & 0 deletions jsExecutor/example3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# import the webdriver
import time

from selenium import webdriver
from selenium.webdriver.common.by import By

options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=options)
driver.maximize_window()
# get method to launch the URL
driver.get("https://demoqa.com/books")
driver.find_element(By.XPATH,"//input[@type='number']").send_keys("5")
# to scroll with Javascript executor
driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")
time.sleep(3)
17 changes: 17 additions & 0 deletions jsExecutor/example4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# import the webdriver
from selenium import webdriver
from selenium.webdriver.common.by import By

options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=options)
driver.maximize_window()
# get method to launch the URL
driver.get("https://www.softwaretestingmaterial.com/")
# to scroll with Javascript executor
driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")
# print the page title in console
print(driver.execute_script('return document.title'))
# print the page URL in console
print(driver.execute_script('return document.URL'))
# to close the browser
driver.close()