A bit stumped here. I am writing a Selenium test for a class project in Python/Django and cannot understand the behavior I am seeing. As part of the test I am clicking on a dropdown menu, then clicking on an option from that menu.
The initial click on the menu works. The menu opens, and then the second click does not. However it's not completely failing -- the click still generates a hover effect over the option in question.
I've done a fair bit of Selenium in the past, so I've tried alot of the standard debugging issues and nothing has worked yet. Among them I've tried double clicking, using Select, using a different selector etc with no luck. I'm going to goof around with ActionChains and SendKeys next, but would like to understand why simpler methods are not working. My code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
from django.contrib.auth.models import User
from django.test.testcases import LiveServerTestCase
from time import sleep
import os
class CreateIssueTestCase(LiveServerTestCase):
def setUp(self):
self.driver = webdriver.Firefox()
user = User.objects.create_superuser(username="username", password="password", email="[email protected]")
user.save()
def tearDown(self):
self.driver.quit()
User.objects.all().delete()
def test_create_issue(self):
self.driver.get("localhost:8081/issue/create")
self.driver.find_element_by_id("id_username").send_keys("username")
self.driver.find_element_by_id("id_password").send_keys("password")
self.driver.find_element_by_id("id_password").send_keys(Keys.ENTER)
sleep(2)
self.driver.find_element_by_id("id_project").click()
sleep(2)
self.driver.find_element_by_css_selector("#id_project > option:nth-child(3)").click()
sleep(2)
self.driver.find_element_by_id("id_issue_type").click()
sleep(2)
The failed click is the second one in the test. There are additional dropdowns on this page that are also behaving the same way.
I'll note I am not seeing any error output from this test. Also, if I don't take further actions, the dropdown menu will remain open with the targeted option highlighted until the test ends.
Thanks,
UPDATE:
I've tried using
self.driver.find_element_by_css_selector("#id_project > option:nth-child(3)").send_keys(Keys.ENTER)
This also has not had the desired effect. Instead of selecting the element in question, it simply closes the drop down menu.
The relevant html as read from firefinder:
<select id="id_project" name="project">
<option value selected="selected">----------</option>
<option value="1">Dummy project1</option>
<option value="2">Dummy project2</option>
</select>