I'm trying to click "Create New Network" by using selenium.
<button type="button" id="dt-refreshBtn" data-label="Create New Network" role="link"><span data-testid="dnxButton-iconButtonContainer" data-awt="networkListing-button-createNew"><i data-testid="dnxButton-icon" title="Create New Network"></i><span data-testid="dnxButton-iconLabel">Create New Network</span></span></button>
<span data-testid="dnxButton-iconButtonContainer" data-awt="networkListing-button-createNew"><i data-testid="dnxButton-icon" title="Create New Network"></i><span data-testid="dnxButton-iconLabel">Create New Network</span></span>
<i data-testid="dnxButton-icon" title="Create New Network"></i>
<span data-testid="dnxButton-iconLabel">Create New Network</span>
I tried several scripts to find the location of "Create New Network" button, but got failed with below reason.
- Message: no such element: Unable to locate element:
- AttributeError: 'list' object has no attribute 'send_keys'
- 'list' object has no attribute 'click'
here are scripts I've tried.
driver.find_element(By.CSS_SELECTOR, "[title='Create New Network']").click()
driver.find_element(By.CSS_SELECTOR, "[data-awt='networkListing-button-createNew']").click()
driver.find_element(By.CSS_SELECTOR, "[id='dt-refreshBtn']").click()
driver.find_element(By.CSS_SELECTOR, "[class='dnx-btn-icon-label']").click()
driver.find_elements(By.XPATH, "//*[@class='dnx-btn-icon-label']").send_keys(Keys.ENTER)
driver.find_elements(By.XPATH, "//button[@class='btn wc-btn--link']")[0].send_keys(Keys.ENTER)
driver.find_elements(By.XPATH, "//*[@id='dt-refreshBtn']").send_keys(Keys.ENTER)
driver.find_element(By.ID, "dt-refreshBtn").send_keys(Keys.ENTER)
driver.find_element(By.CSS_SELECTOR, "[data-testid='dnxButton-icon']").send_keys(Keys.ENTER)
driver.find_element(By.CSS_SELECTOR, "[data-testid='dnxButton-iconLabel']").send_keys(Keys.ENTER)
driver.find_elements(By.CSS_SELECTOR, "[data-awt='networkListing-button-createNew']").click()
driver.find_element(By.CSS_SELECTOR, "[title='Create New Network']").click()
driver.find_elements(By.XPATH, "//*[@id='dt-refreshBtn']").click()
could you please help this one ?
CodePudding user response:
Now let's go through each error .find_elements() is used for multiple elements and .click() | send_keys() is used for a single element is why the majority will give 'list' object has no attribute 'click' unless you access the individual element.
.send_keys() is normally used for input tags or textareas and you'd want .click() for the button tag.
Now some valid xpaths would be like so:
driver.find_element(By.XPATH, "//button[@class='btn wc-btn--link']").click()
would be a valid xpath if that is the only button class with that class name.
driver.find_element(By.XPATH, "//button[@id='dt-refreshBtn']").click()
If this still doesn't find check if the element is under iframes or shadow roots.
CodePudding user response:
driver.find_element(By.XPATH, "//button[@id='dt-refreshBtn']").click()
should work