How To: Find Element In Selenium (3 Min) Using Python In PyCharm
In this tutorial, you'll learn how to find web element in Selenium using Python.
—
Facebook: https://www.facebook.com/GokceDBsql
—
Video Transcript:
—
Hi guys, this is Abhi from Gokcedb. In this video, you're going to learn how to extract data from a web table in Selenium using Python. Let's start by looking at the test scenario on mozilla.org.
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.
I have a conf test.py file where I'm defining the driver fixture function to initialize the Chrome web driver in the test file. I'm passing the driver fixture function as the first argument to my test function. On line 5, I'm using driver.get method to go to the mozilla.org URL.
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.
Connect MySQL In Python: https://www.youtube.com/watch?v=0qBctY82et0
—
from selenium import webdriver
from selenium.webdriver.common.by import By
import os
import time
root_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
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
driver.implicitly_wait(2)
driver.get("https://www.amazon.com/")
time.sleep(2) # only used for the demo
driver.find_element(By.ID, "twotabsearchtextbox").send_keys("sunglasses")
time.sleep(2) # only used for the demo
driver.find_element(By.ID, "nav-search-submit-button").click()
keyword = "Raz-Ban"
if keyword in driver.page_source:
print("{} keyword found in the page source: Test successful".format(keyword))
else:
print("{} keyword not found in the page source: Test failed".format(keyword))
time.sleep(2) # only used for the demo
driver.quit()
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «How To: Find Element In Selenium (3 Min) Using Python In PyCharm», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.