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

asked Sep 16, 2016 at 12:24

1 Answer 1

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()
alecxe
11.4k11 gold badges52 silver badges107 bronze badges
answered Sep 16, 2016 at 12:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.