0

Could someone please tell me how can I select a dynamic element using selenium?

I would like to select the "limit-order" element.

<div class="tab-control" id="uniqName_0_85" widgetid="uniqName_0_85">
    <span data-tab="market-order" class="tab-item tab-active">Market</span>
    <span data-tab="limit-order" class="tab-item">Limit</span>
    <span data-tab="stop-order" class="tab-item">Stop</span>
    <span data-tab="stop_limit-order" class="tab-item">Stop Limit</span>
</div>

I tried this but no luck:

btn_limit_name_xpath = '//div[contains(@class,"tab-control")]/span[2]'
btn_limit = browser.find_element_by_xpath(btn_limit_name_xpath)
btn_limit.click()
  • Does this answer your question? [How do I find an element that contains specific text in Selenium Webdriver (Python)?](https://stackoverflow.com/questions/12323403/how-do-i-find-an-element-that-contains-specific-text-in-selenium-webdriver-pyth) – Dhamo Jun 12 '20 at 11:48

1 Answers1

0

What sometimes does the job for me is copy the full xpath instead of the shorter one.

If that doesn't work either, you could try and check this out.

They show you how you can use an xpath to find a specific piece of text and select the object in that way. So in your case you could try and find it by searching for 'limit'.

Jem
  • 557
  • 9
  • 28
  • 1
    Hey, Thank you. The copying the full path did not work but I could use the information the link, and now my program is working. – Peter Ryans Jun 12 '20 at 11:35