123ArticleOnline Logo
Welcome to 123ArticleOnline.com!
ALL >> Computer-Programming >> View Article

Usage Of Javascript With Python Selenium Testing

By Author: Siyaram ray
Total Articles: 387

For instance, since WebDriver recreates end-client association, it is regular that it will decline to tap on a component that isn't unmistakable to end client. There can be a few other comparative reasons or situations. In these cases, can depend on Selenium Training in Bangalore JavaScript to click or play out a few activities on that web component and this javascript articulation can be executed through WebDriver.
You can do everything that the WebElement interface does and more with Javascript.
What is JavaScript?
JavaScript is a scripting dialect that keeps running on customer side, i.e on the program and does some enchantment things when you surf through site pages.
How would we do this?
Python selenium WebDriver gives an in-constructed technique
driver.execute_script("some javascript code here");
There are two different ways through which we can execute JavaScript inside the program.
Executing JavaScript at record root level:
For this situation we catch the component, that we need to work with, utilizing javascript gave strategies, at that point pronounce a few activities on it and execute this javascript utilizing WebDriver.
javaScript = "document.getElementsByName('username')[0].click();"
What are we doing here?
• We are examining and bringing the component by one of its property 'name' (Also id and class properties can be utilized) utilizing javascript.
• Declare perform click activity on a component utilizing javascript.
• Call execute_script() technique and pass the javascript that we made as String esteem
Notice [0] in getElementsByName('username')[0] proclamation. JavaScript capacities getElementsByName, getElementsByClassName and so on restore every single coordinating component as a cluster and for our situation we have to follow up on first coordinating component which can be gotten to through record [0]. On the off chance that you comprehend what you are doing i.e. on the off chance that you know list of component that you need to work, you can straightforwardly utilize the list like getElementsByName('username')[2]
While on the off chance that you are utilizing JavaScript work 'getElementById', you no compelling reason to utilize any ordering as it will return just a single component.
While on execution, WebDriver will infuse the JavaScript explanation into the program and the content will play out the activity; in our model perform click task on the objective component. This javascript has its very own namespace and does not meddle with javascript in real website page.
Executing JavaScript at component level:
For this situation we catch the component that we need to work with utilizing webdriver, at that point we proclaim a few activities on it utilizing javascript and execute this javascript utilizing WebDriver by passing web component as a contention to the javascript. Is it confounding? Disappoints break
userName = driver.find_element_by_xpath("//button[@name='username']")
driver.execute_script("arguments[0].click();", userName)
Stage 1: Inspect and catch the component utilizing webdriver gave strategies like 'find_element_by_xpath'
userName = driver.find_element_by_xpath("//button[@name='username']")
Stage 2: Declare perform click activity on the component utilizing javascript.
Stage 3: Call execute_script() technique with the javascript explanation that we made as String worth and webelement caught utilizing webdriver as contentions
driver.execute_script("arguments[0].click();", userName)
The over two lines of code can be abbreviated to beneath configuration where we discover component utilizing webdriver, proclaim some javascript capacities selenium training institutes in Marathahalli and execute the javascript utilizing webdriver.
driver.execute_script("arguments[0].click();", driver.find_element_by_xpath("//button[@name='username']"))
Another all the more every now and again confronted issue is looking to the base of the website page and you can play out this task in a solitary line of code
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
How to return esteems?
Other vital part of javascript agent is, it very well may be utilized to get esteems from web component; That implies execute_script() strategy can return esteems.
For instance:
print driver.execute_script('return document.getElementById("fsr").innerText')
Note that on the off chance that you need something returned by javascript code, you have to utilize return. Likewise components can be situated with selenium and go into the content.

More About the Author

best institute for selenium training in Bangalore – Infocampus. Infocampus is an excellence training center for selenium courses in Bangalore. At Infocampus, selenium training is focused on practical and real time examples. Contact Infocampus at 8884166608 or visit http://infocampus.co.in/best-selenium-testing-training-center-in-bangalore.html for complete details on selenium training.

Total Views: 20Word Count: 630See All articles From Author

Computer Programming Articles

1. Selenium Testing With Python And Why It Makes Sense
Author: Siyaram ray

2. Though Rudi Says The Rocket League Crew Is Cognizant
Author: lolgaonline

3. Basic Python Training
Author: zenitech

4. For Selenium Testing - Which One Is Best For You Either Java Or Python
Author: Siyaram ray

5. Avail Smart Video Surveillance Software From Reliable Company For Better Output
Author: Devline

6. Benefits Of Selenium - Test Automation Tool
Author: Siyaram ray

7. Designing And Execution Of Selenium Test Automation Framework
Author: Siyaram ray

8. Microsoft Access Queries And How Important They Are In Your Database
Author: Ben Beitler

9. Восхождение На Вулкан Ринджани. Ломбок. Индонезия (rinjani)
Author: Armando Kozak

10. The Future Of Innovation In The Era Of Artificial Intelligence
Author: Charlotte

11. Product Engineering Services From Enlume Inc
Author: Srikanth reddy

12. Www Mcafee Com Activate | Mcafee Com/activate | Is Mcafee Antivirus Not Functioning Properly?

13. 123.hp Setup | 123.hp Com/setup | 123.hp Setup Officejet
Author: setup desk

14. Best Software Training And Placement Company In Hyderabad
Author: hema sri

15. Professional Private Investigator Milwaukee Services To Unravel The Truth
Author: Milwforensics

Login To Account
Login Email:
Forgot Password?
New User?
Sign Up Newsletter
Email Address: