I\'m using Python-Webdriver to automate a \"click\" action. Here is my code:
from selenium.webdriver.common.by import By
from selenium import webdriver
from
According to the documentation, you can use either find_element_by_* shortcuts, or find_element() and find_elements() "private" methods directly:
Apart from the public methods given above, there are two private methods which might be useful with locators in page objects. These are the two private methods: find_element and find_elements.
Example usage:
from selenium.webdriver.common.by import By driver.find_element(By.XPATH, '//button[text()="Some text"]') driver.find_elements(By.XPATH, '//button')
But, in your case, instead of passing 2 parameters to find_element(), you are passing a single one - a tuple NEWS_OPTION. You just need to unpack the tuple into positional arguments:
NEWS_OPTION = (By.ID, 'blq-nav-news')
myDynamicElement = driver.find_element(*NEWS_OPTION)
Or, just as an alternative, you could use keyword arguments also:
NEWS_OPTION = {'by': By.ID, 'value': 'blq-nav-news'}
myDynamicElement = driver.find_element(**NEWS_OPTION)
And, also, whenever you have any doubts how things should work, just dig up the source code and clarify it for yourself. In this case, see how find_element_by_id() method is actually implemented:
def find_element_by_id(self, id_):
"""Finds an element by id.
:Args:
- id\_ - The id of the element to be found.
:Usage:
driver.find_element_by_id('foo')
"""
return self.find_element(by=By.ID, value=id_)