Why is my selenium code failing when trying to check that there is a certain word inside of the URL?

  Kiến thức lập trình

I am using my terminal to run an automated test, and I want to check that the word is inside the URL. I am thinking maybe I have a syntax error as I am new to using selenium.

In VSCode this is what I have so far, and I was able to successfully get the chrome browser to open as well as have it input the site name, but I am unable to get it to scan the URL string. Could you help explain what is the issue?

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
import unittest
import time

# Define the MyTestCase class
class MyTestCase(unittest.TestCase):
    def setUp(self):
        self.browser = webdriver.Chrome()

    def test_search_bar(self):

        # Wait for the search bar element to be interactable
        wait = WebDriverWait(self.browser, 10)
        search_bar = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'input[type="text"]')))  # Use "text" instead of "textarea"

        search_bar.send_keys('Amazon.com' + Keys.ENTER)
        self.assertIn('Amazon.com', search_bar.get_attribute('value'))

        # Wait for the URL to update

        self.assertIn('Amazon', self.browser.current_url)  # Check for "Amazon" in the URL

if __name__ == '__main__':

New contributor

Reem Khattab is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.