username?name attribute is different from id, class, or tag.To find an element by its name attribute in Selenium Python, use By.NAME. Other locators target different attributes or tags.
search exists on the page?from selenium import webdriver from selenium.webdriver.common.by import By driver = webdriver.Chrome() driver.get('https://example.com') element = driver.find_element(By.NAME, 'search') print(element.tag_name)
If the element with the specified name is not found, Selenium raises a NoSuchElementException. It does not return None or an empty string.
email is present on the page. Which assertion is correct?from selenium.webdriver.common.by import By from selenium.common.exceptions import NoSuchElementException try: element = driver.find_element(By.NAME, 'email') # Assertion here except NoSuchElementException: assert False, 'Element with name email not found'
The best way to confirm the element found has the correct name attribute is to assert element.get_attribute('name') == 'email'. Other assertions check unrelated properties.
password?element = driver.find_element('name', 'password')
The correct locator syntax uses By.NAME from selenium.webdriver.common.by. Passing a plain string 'name' causes an error.
Option A correctly uses a synchronous pytest fixture with module scope, initializes the driver, yields it for tests, and quits after all tests in the module. Async fixtures or calling driver.close() prematurely are incorrect.