1

I'm trying to access the div element by it's content (which is text) using the xpath, but it's not able to find the element.

I have a number of td items:

<tr role="listitem">
<td class="cellDark" height="20" align="left" style="WIDTH:52px;OVERFLOW:hidden;padding-top:0px;padding-bottom:0px;;white-space: nowrap;">
<div style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;WIDTH:48px;" cellclipdiv="true" role="presentation">TRY</div>
</td>
</tr>

<tr role="listitem">
<td class="cellDark" height="20" align="left" style="WIDTH:52px;OVERFLOW:hidden;padding-top:0px;padding-bottom:0px;;white-space: nowrap;">
<div style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap;WIDTH:48px;" cellclipdiv="true" role="presentation">COL</div>
</td>
</tr>

I want to click on the TRY div element. It actually appears in a dropdown (which doesn't have any unique identifiers in it - ID or class or anything). They change dynamically, so I have to rely on the text only.

I've tried using this approach to find the TRY div element:

driver.find_element_by_xpath("//div[contains(text(), 'TRY')]").click()
driver.find_element_by_xpath("//*[contains(text(), 'TRY')]").click()

But this results into following error:

ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with

0

This is because you are trying to access an element which hasn't been loaded yet.

You need to first access the dropdown menu in order to activate the elements inside the dropdown list. After that the XPath you have mentioned will work:

driver.find_element_by_xpath("//div[contains(text(), 'TRY')]").click()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.