How To Select Dropdown Value In Selenium (2 Min) Using Python

preview_player
Показать описание
In this tutorial, you'll learn how to select dropdown value in Selenium using Python and PyTest.


Video Transcript:


Line 13, I'm clicking on the search submit button. On line 15, I'm using the get attribute method to get the inner HTML text of the first search result. Finally, on line 20, I'm asserting whether the keyword game appears in the text or not.

Now let's run this test to see what the execution looks like as you can see the test passed. Watch what happens if I change the keyword game to XYZ and re-execute the test. This time our test failed as expected due to an assertion error.

Finally, export the test results button. There you have it. Make sure you like, subscribe, and turn on the notification bell.

Until next time. Make sure you like, subscribe, and turn on the notification bell. Until next time.



def test_dropdown(driver):

'/div[2]/div[4]/div/div/div/div/div/div[2]'
'/div/div/div[1]/h2/a/span').get_attribute('innerHTML')

print("text:", text)

import pytest
from selenium import webdriver
import os

def driver():
driver = webdriver.Chrome(executable_path=root_dir + '/resources/chromedriver')
yield driver
Рекомендации по теме