@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 selenium.webdriver.common.by import By
from selenium.webdriver.support.select 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(house.name))
quoted_pk = quote(str(house.pk))
self.selenium.get(
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.selenium.get(
self.live_server_url + reverse("admin:admin_widgets_room_add")
)
select_house = Select(self.selenium.find_element(By.ID, "id_house"))
select_house.select_by_value(quoted_pk)
# Create a new Room and associate it with the House created above
room = Room.objects.create(name='onebed', house=house)
room_name = str(room.name)
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.CSS_SELECTOR,save_button_css_selector)
self.selenium.find_element(By.ID, "view_id_house").click()
self.selenium.back()
# 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)
self.selenium.back()
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/tests.py”, 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/webdriver.py”, 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/webdriver.py”, line 440, in execute
self.error_handler.check_response(response)
File “/home/yemisi/PycharmProjects/django/venv/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py”, line 245, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: [id=“id_house”]