0
<td role="presentation" valign="top" class=" x-trigger-cell x-unselectable" style="width:28px;" id="ext-gen1147">
<div class="x-trigger-index-0 x-form-trigger x-form-arrow-trigger x-form-trigger-first rp-icon-expanded" role="presentation" id="ext-gen1146">
</div></td>

im trying to click this div elementbut throwing exception.My code is:

driver.find_element_by_xpath("//div[@id='ext-gen1146']").click()
driver.find_element_by_xpath("//*[@id='ext-gen1147']").click()
driver.find_element_by_xpath("//div[@class='x-trigger-index-0 x-form-trigger x-form-arrow-trigger x-form-trigger-first rp-icon-expanded' and @id='ext-gen1146']")

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='ext-gen1147']"} (Session info: chrome=80.0.3987.163)

enter image description here

Divya Mani
  • 203
  • 1
  • 3
  • 15

4 Answers4

0

Try below solution and check your element is not dynamic and its not inside the iframe, if its in iframe then you have to switch to it and then click on your eelement.

wait.until(EC.element_to_be_clickable((By.ID, "ext-gen1147"))).click()

or

wait.until(EC.element_to_be_clickable((By.XPATH, "x-trigger-index-0 x-form-trigger x-form-arrow-trigger x-form-trigger-first rp-icon-expanded"))).click()

Note : please add below imports to your solution

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait

To switch to iframe you can use below code, Make sure you have only one iframe or else you can use ID/Name of iframe to identify correct element before switching:

 iframe = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.TAG_NAME, 'iframe')))
 driver.switch_to.frame(iframe)
SeleniumUser
  • 4,065
  • 2
  • 7
  • 30
0

I think maybe you need to wait for visibility first, maybe this helps you https://stackoverflow.com/a/19537085/2069610... for example:

WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id<"ext-gen1146>));
lhd
  • 436
  • 4
  • 16
0

To click on dynamic element Induce WebDriverWait() and element_to_be_clickable() and following css selector.

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div.rp-icon-expanded[id^='ext-gen'][role='presentation']"))).click()

You need to import following libraries.

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
KunduK
  • 32,888
  • 5
  • 17
  • 41
0

you can try Actions class to click on the expected element -

Actions actions = new Actions(driver);
actions.click(element).build().perform();

if this also not works try using JavascriptExecutor

JavascriptExecutor executor = (JavascriptExecutor) driver;
executor..executeScript("arguments[0].click();", element);