I'am trying to make a bot that auto logins to a website. In order to write the username I'm trying to use
driver.find_element_by_variable("username").send_keys(username)
When I'm looking that spesific variable from website on inspect the varible is two word like matinput formcontrolname.
On any other website if that varible is one word like id I simply write id after by_ and it works what can I do in this situation?
CodePudding user response:
Selenium won't allow you to use:
find_element_by_variable()
but you have to use either of the predefined Locator Strategies as listed in the By implementation which are as follows:
CLASS_NAME= class namedriver.find_element(By.CLASS_NAME, "element_classname")CSS_SELECTOR= css selectordriver.find_element(By.CSS_SELECTOR, "element_css_selector")ID= iddriver.find_element(By.ID, "element_id")LINK_TEXT= link textdriver.find_element(By.LINK_TEXT, "element_link_text")NAME= namedriver.find_element(By.NAME, "element_name")PARTIAL_LINK_TEXT= partial link textdriver.find_element(By.PARTIAL_LINK_TEXT, "element_partial_link_text")TAG_NAME= tag namedriver.find_element(By.TAG_NAME, "element_tag_name")XPATH= xpathdriver.find_element(By.XPATH, "element_xpath")
