XPATH doesnt press a clickable button Python

时间:2015-07-28 15:36:57

标签: python html selenium selenium-webdriver

my problem is that the first on is clicking and the second one doesnt and i dont undersatand why

WebDriverWait(rootdiv, 10).until(EC.element_to_be_clickable((By.XPATH, "//li[@onclick[contains(.,JTC)]]")))


rootdiv.find_element_by_xpath("//li[@onclick[contains(.,'JTC')]]").click()

WebDriverWait(depdiv, 10).until(EC.element_to_be_clickable((By.XPATH, "//li[@onclick[contains(.,AJU)]]")))

depdiv.find_element_by_xpath("//li[@onclick[contains(.,'AJU')]]").click()

depdiv and root div are children to look under for the certain li cause the root changes from the first to the second.. i've checked that the div is visible and in the first one, its clicking, the second time it cant find the object and im getting a time error

part of the code im trying to fed from..

<div class = "divCombo4">
   <ul><li>....</li><ul>
   <ul><li>...</li><ul>
</div>

and my depdiv is rooting to the find_element_by_id("divCombo4")

one of those ul li contains

onclick="selecionou('AJU', this,'.txtBusca4', 'false', 'destino', 'Estouem2', 'AJU');"

1 个答案:

答案 0 :(得分:0)

First of all, you need a dot to make the expressions context-specific. Also, the wait.until() returns a WebElement instance and you can use it instead of issuing a "find element" command again:

WebDriverWait(rootdiv, 10).until(EC.element_to_be_clickable((By.XPATH, ".//li[@onclick[contains(.,JTC)]]"))).click()

WebDriverWait(depdiv, 10).until(EC.element_to_be_clickable((By.XPATH, ".//li[@onclick[contains(.,AJU)]]"))).click()