'Clicking on a link using Selenium Python
Please need your support to click on a link in the following:
I tried the below code but doesn't work:
web.find_element(By.XPATH,'//*[@id="HUI_i_0"]/table/tbody/tr/td/a').click()
It gives me error:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="HUI_i_0"]/table/tbody/tr/td/a"}
Solution 1:[1]
Try to use link text to locate element:
web.find_element(By.LINK_TEXT,'Subscriber Administration').click()
If link is dynamic try to add wait
Solution 2:[2]
The desired element is a dynamic element, so to click() on the clickable element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:
Using PARTIAL_LINK_TEXT:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "tbody > tr > td.treeNode > a"))).click()Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.btn.signin-btn.sbLoginBtn > span.btf-text"))).click()Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(., 'Subscriber Administration')]"))).click()Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
References
You can find a couple of relevant discussions on NoSuchElementException in:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | JaSON |
| Solution 2 | undetected Selenium |

