How To: Find Element In Selenium (3 Min) Using Python In PyCharm

preview_player
Показать описание
In this tutorial, you'll learn how to find web element in Selenium using Python.



Video Transcript:


I want to this specific URL and read the items sold in the August 2016 table more specifically. I want to assert whether the total number of items sold in Amsterdam is equal to 315 or not. Now, let's look at the test directory.

On line 7, I'm reading the text of the sixth row of the item sold on the table. Line 12, I'm splitting the table row with the space delimiter and looping through the individual items with the for loop if the item is of the type INT. I add it to the total variable else. I ignore the item.

Finally, on line 19, I'm asserting whether the total is equal to 315 or not. Now let's run this program to see what the output looks like. As you can see since the total came out to 315.

Our test passed. Let's see what happens if I change the total to 320 and rerun the program. This time our test failed as expected.

Finally to export the test results in an HTML format click on the export test results button. There you have it. Make sure you like, subscribe, and turn on the notification bell.

Until next time.



from selenium import webdriver
import os
import time

driver = webdriver.Chrome(executable_path=root_dir + '/resources/chromedriver')

# Time in seconds driver should wait when searching for an element if it is not immediately present

keyword = "Raz-Ban"
print("{} keyword found in the page source: Test successful".format(keyword))
else:
print("{} keyword not found in the page source: Test failed".format(keyword))

Рекомендации по теме