How To: XPath Contains Function (2 Min) In Selenium Using Python | In PyTest & PyCharm смотреть онлайн
In this tutorial, you'll learn how to use the XPath contains function in Selenium using Python in PyTest & PyCharm.
—
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 use XPath content in Selenium using Python. Let's start by looking at the scenario.
I want to go to amazon.com and search for the keyword sunglasses. In the search result, I want to click on the product that has the label amazon's choice. Next, I want to assert whether the keyword UV400 protection appears on the product page.
Next, let's look at the test directory. I have a conf test.py file that contains the driver fixture function. This function initializes the Chrome driver and returns the driver object in my test file.
I'm passing the driver fixture as the first argument to my test function. On line 9, I'm using the get method to go to amazon.com. Line 11, I'm finding the search text box by id and typing the sunglasses keyword in it.
On line 13, I'm clicking on the search submit button. On line 15, use the XPath containing the function to search for any id that contains the keyword amazon's choice label and click on it. Next, I'm asserting whether the keyword UV400 protection appears in the paid source or not.
Finally, on line 20, I'm closing the browser. Let's run this test to see what the execution looks like. Note, I'm only using time dot sleep to artificially slow down the execution.
As you can see the test passed. Let's see what happens if I change the keyword to UV500 instead of UV400. As you can tell this time the test failed as expected.
Now let's look at how to find the web element ids from the Chrome browser. Start by clicking on the button with three dots then choose developer tools from the more tools drop-down. Now click on the inspect button then hover over the web element you are interested in.
Now click on it to get the corresponding HTML code and grab the ID from there. 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
—
import pytest
from selenium import webdriver
import os
@pytest.fixture(scope="session")
def driver():
root_dir = 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)
return driver
import pytest
import time
from selenium.webdriver.common.by import By
# pass the driver fixture as the first argument
@pytest.mark.test_keyword_in_search_result
def test_keyword_in_search_result(driver):
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()
time.sleep(2) # only used for the demo
driver.find_element(By.XPATH, "//*[contains(@id,'amazons-choice-label')]").click()
time.sleep(2) # only used for the demo
assert "UV500 PROTECTION" in driver.page_source
driver.quit()
--
Video Transcript
--
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «How To: XPath Contains Function (2 Min) In Selenium Using Python | In PyTest & PyCharm» бесплатно и без регистрации, вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.