It may so happen that in some real-time projects, Selenium WebDriver cannot perform an action on a particular web element. For example, since WebDriver simulates end-user interaction, it is natural that it will refuse to click on an element that is not visible to the end user (sometimes it also happens even though the web element is visible on the page). There can be several other similar reasons or scenarios.
Python Selenium WebDriver provides a built-in method:
 in the
getElementsByClassName , and so on return all matching elements as an array. In our case, we need to act on the first matching element that can be accessed via
index  . If you know what you are doing, i.e., if you know the index of the element you want to operate, you can directly use the index, such as
getElementById ', you do not need to use any indexing, as it will return only one element (‘id’ should be unique).
Is this confusing? Let's break it down.
userName = driver.find_element_by_xpath("//button[@name='username']") driver.execute_script("arguments.click();", userName)
Step 1: Inspect and capture the element using WebDriver-provided methods like '
userName = driver.find_element_by_xpath("//button[@name='username']")
Step 3: Call
Another issue faced more frequently is the need to scroll to the bottom of the web page. You can perform this operation in a single line of code:
userName = driver.find_element_by_xpath("//button[@name='username']") password = driver.find_element_by_xpath("//button[@name='password']") driver.execute_script("arguments.click();arguments.click();", userName, password)
In this case, usage of the order of web elements matters. Accessing
driver.execute_script("arguments.click();arguments.click();", userName, password)
execute_script() method can return values.
print driver.execute_script('return document.getElementById("fsr").innerText')
Scenario 1: We're trying to read a property using '
print driver.execute_script('return document.getElementById("fsr").innerText') ' but there is no such element available in the web page. We get the following message in the exception trace:
selenium.common.exceptions.WebDriverException: Message: unknown error: Cannot read property 'innerText' of null
print driver.execute_script('document.getElementById("fsr").clic();') '. (Note the spelling mistake in the
click() method name.)
selenium.common.exceptions.WebDriverException: Message: unknown error: document.getElementById(...).clic is not a function
Best Mobile App Development Company India, WebClues Global is one of the leading web and mobile app development company. Our team offers complete IT solutions including Cross-Platform App Development, CMS & E-Commerce, and UI/UX Design.
We are custom eCommerce Development Company working with all types of industry verticals and providing them end-to-end solutions for their eCommerce store development.
Know more about Top E-Commerce Web Development Company
As one of the best Web Application Development Company, it provides a fine quality mobile app development service at an affordable price. Especially, it encourage start-ups that have unique ideas, by offering a more competitive price
HireFullStackDeveloperIndia is rated as one of the top Web Application Development Company in India by various industry magazines and review sites. They have a right blend of award-winning designers, expert programmers and Google certified digital marketers which make them a unique one-stop solution for hundreds of our clients, spread across all countries.
A Good website reflects not only your business but also it is one of the main factors why a potential customer would convert into Client. A good website design helps increase traffic driving leads to grow business. The best web design company create a custom design for each corporate website so as to help them meet their business goals.