Contributing to #30386. Having Issue With Selenium Test

@carltongibson and anyone who has an idea on what to do can please suggest it to me. Thank you

I’m trying to run this selenium test below. I created a House with primary key that needs quoting which I quoted and I Create a new Room and associate it with the House I created. So I want to Check that the Room was created and is listed in the change form and also check that the house has been associated with.

def test_create_houses_and_room(self):
from import By
from import Select
self.admin_login(username=“super”, password=“secret”, login_url=“/”)

    # Create a new House with a PK that needs quoting
    house = House.objects.create(name='_40')
    house_name = str(quote(
    quoted_pk = quote(str(
        self.live_server_url + reverse("admin:admin_widgets_house_add")
    self.selenium.find_element(By.ID, "id_name").send_keys(house_name)
    self.selenium.find_element(By.NAME, "_save").click()

    # Check that the new House was created and listed in the change form
        self.live_server_url + reverse("admin:admin_widgets_room_add")
    select_house = Select(self.selenium.find_element(By.ID, "id_house"))


    # Create a new Room and associate it with the House created above
    room = Room.objects.create(name='onebed', house=house)
    room_name = str(
    self.selenium.find_element(By.ID, "id_name").send_keys(room_name)

    self.selenium.find_element(By.NAME, "_save").click()

    self.selenium.find_element(By.ID, "id_house").click()

    save_button_css_selector = ".submit-row > input[type=submit]"

    self.selenium.find_element(By.ID, "view_id_house").click()

   # Check that the House is linked to the Room and listed in the change form

    self.selenium.find_element(By.ID, "id_house").click()

    save_button_css_selector = ".submit-row > input[type=submit]"
    self.selenium.find_element(By.CSS_SELECTOR, save_button_css_selector)
    self.selenium.find_element(By.ID, "view_id_house").click()
    self.wait_for_value("#id_name", house_name)

But I’m getting this error,

ERROR: test_create_houses_and_room (admin_widgets.tests.RelatedFieldWidgetSeleniumPrimaryKeyTests)

Traceback (most recent call last):
File “/home/yemisi/PycharmProjects/django/tests/admin_widgets/”, line 1850, in test_create_houses_and_room
self.selenium.find_element(By.ID, “id_house”).click()
File “/home/yemisi/PycharmProjects/django/venv/lib/python3.10/site-packages/selenium/webdriver/remote/”, line 830, in find_element
return self.execute(Command.FIND_ELEMENT, {“using”: by, “value”: value})[“value”]
File “/home/yemisi/PycharmProjects/django/venv/lib/python3.10/site-packages/selenium/webdriver/remote/”, line 440, in execute
File “/home/yemisi/PycharmProjects/django/venv/lib/python3.10/site-packages/selenium/webdriver/remote/”, line 245, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: [id=“id_house”]

So here, the #id_house selector isn’t matching.

If you run with --parallel=1 --pdb the execution should stop at that point, and you can interact with the browser normally to inspect the DOM and see what’s going on.

(As an alternative you can add a breakpoint() call on the line above the failing one to stop the test there too.)

Thank you, I forgot to update it here, I already fixed it and made a PR.