I've written a code to test a page in python with selenium. The code works but now I'm trying to rewrite it better.
I have created a locators.py file as described in the following documentation: selenium python binding - page objects.
For simple locators this is straightforward.
This is what I've done so far:
from selenium.webdriver.common.by import By
class PhotoHomePageLocators(object):
"""A class for photographer home page locators. All photographer interface home page locators should come here"""
add_new_project_btn = (By.CLASS_NAME, 'addProject')
view_all_projects_btn = (By.CLASS_NAME, 'viewAllProjects')
class NameCoverPageLocators(object):
"""A class for name and cover home page locators. All name and cover page locators should come here"""
project_name_txt_box = (By.XPATH, '//*[@id="rform_pt2_0"]')
client_name_txt_box = (By.XPATH, '//*[@id="rform_pt2_1"]')
client_email_txt_box = (By.XPATH, '//*[@id="rform_pt2_2"]')
but I have the following line in my code which I'm uncertain how to write so it fits the above syntax:
driver.find_element_by_class_name('coverUpload').find_element_by_class_name('pButton').click()
I'm locating a class within a class, there are several pButton classes in the page, but only one inside the coverUpload class.
//*whenever possible, they are very inefficient. Providing the name of tag is better. Or even better, when using@id, is usingBy.ID