1
votes

I have a problem finding an Element (Button to click) with my code. I am using Selenium IDE to find the xpath or css selector of the element. Strangely the Selenium IDE does find it but my code doesn't.

The element i want to select is a button, when clicked a dropdown appears and i need to click on another button.

  1. Button (button class="js-select uk-button uk-button--select">)
  2. Button(li data-field="sapOrderNumber">Auftragsnummer

Here is the html of the class i want to select:

<div class="uk-button-dropdown uk-margin-right" data-uk-dropdown="{mode:'click'}" aria-haspopup="true" aria-expanded="false">
        <button class="js-select uk-button uk-button--select">
            <span>Filter auswählen</span>
            <i class="icon-arrow-left"></i>
        </button>
        <div class="uk-dropdown uk-dropdown-close uk-dropdown-bottom uk-dropdown--select" aria-hidden="true">
            <ul class="js-filter-select uk-nav uk-nav--select">
                    <li data-field="articleNumber">Artikelnummer</li>
                    <li data-field="dateRange">Zeitraum</li>
                    <li data-field="sapOrderNumber">Auftragsnummer</li>
                    <li data-field="personalReference">persönliche Referenz</li>
                    <li data-field="shipTo">Lieferadresse</li>
                    <li data-field="orderType">Auftragsart</li>
            </ul>
        </div>
    </div>

Screenshot of Selenium IDE (Selenium IDE does find and click on the button) 1

I have tried to find the element with the following code:

driver.find_element_by_xpath("//ul[@id='tabs-orderbook']/li/div/div/div/div/div/button").click()
driver.find_element_by_xpath("//button").click()
driver.find_element_by_css_selector(.uk-margin-right > .js-select").click()

this is the error message i get:

NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//ul[@id='tabs-orderbook']/li/div/div/div/div/div/button"}

I have looked for an answer quite a while now and getting frustrated. I would be really grateful for any help or tips.

I am using Chrome ( Version 77.0.3865.120 ), chrome webdriver (Version 77.0.3865.40), selenium (Version 3.141.0)

ps. This is my first question on stack overflow so if you have any tips regarding how i ask questions i would be really grateful as well.

Thanks a lot and have a great day. :D

1
Please mention the Selenium version, Browser name, version and the driver version used. - Naveen
Have you tried adding a pause between the clicks? Many times, the animation of opening the dropdown is slower than the running test so you need to add some kind of wait - MivaScott

1 Answers

0
votes

As per my understanding you want to select the buton with class name "js-select uk-button uk-button--select"..below is the xpath for that,

//button[contains(@class, 'js-select uk-button uk-button--select')]

For selecting the drop down value below is the xpath,

//li[contains(text(), 'Auftragsnummer')]