0

I have the following element in the DOM:

<div id="sourceListDiv">
    <select id="sourceList" onkeydown="uil.handleKeyDown(this)" size="15" ondblclick="uil.HandleDBLClickOnSourceList(this);">
        <option id="{88175AC5-E53B-4E67-826C-0E2A43A4E910}">Approval&nbsp;Process&nbsp;Type&nbsp;-&nbsp;(Approval&nbsp;Process&nbsp;Type)</option>
        <option id="{3CFB4862-B80B-45AD-B21E-82E377A59CD5}">Days&nbsp;Before&nbsp;Next&nbsp;Billing&nbsp;-&nbsp;(Calculates&nbsp;Days&nbsp;before&nbsp;Next&nbsp;Installment&nbsp;Due&nbsp;Date)</option>
        <option id="{800F55B6-1603-4FD5-ADCD-D030C2EFBAC9}">Days&nbsp;In&nbsp;Collection&nbsp;-&nbsp;(Calculates&nbsp;Days&nbsp;in&nbsp;Collection)</option>
        <option id="{5531AA05-A347-472C-8B5B-2CFAFE5542E6}">Days&nbsp;Past&nbsp;Due&nbsp;-&nbsp;(Delay&nbsp;days&nbsp;coming&nbsp;from&nbsp;Host)</option>
        <option id="{D7D18409-9685-4EEA-B664-2570288566D0}">Days&nbsp;in&nbsp;Strategy&nbsp;-&nbsp;(Days&nbsp;in&nbsp;Strategy)</option>              
    </select>
</div>

And need to use xpath in order to locate one of the options.

The code I am executing is this:

            searchForLookUpResult(itemName);
            clickOnLookUpSearchButton();
            System.out.println(driver.findElement(By.xpath("//div[@id='sourceListDiv']/select/option")).getText());
            itemName = itemName.replace(" ", "${nbsp}");
            System.out.println(itemName);
            driver.findElement(By.xpath("//option[text()=\"" + itemName + "\"]")).click();
            driver.findElement(By.xpath("ui_okButton")).click();
            if (frameContext.equals("Internal")) { switchToFrameManually(1); }
            else switchToDialogFrame();

But, it fails when it reaches the: driver.findElement(By.xpath("//option[text()=\"" + itemName + "\"]")).click(); part with the error:

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//option[text()="Days${nbsp}Past${nbsp}Due${nbsp}-${nbsp}(Delay${nbsp}days${nbsp}coming${nbsp}from${nbsp}Host)"]"}

I took the ${nbsp} part from selenium in order to handle the   in the DOM (saw it here: https://stackoverflow.com/questions/247135/using-xpath-to-search-text-containing-nbsp)

The itemName parameter should be passed as a String because I am using it in a previous part of the same method. The value of the String passed is: "Days Past Due - (Delay days coming from Host)".

So far, all efforts have failed, with or without replace(), typing the ${nbsp} and or   or its \u00A0 replacement. So any hints will be highly appreciated.

1 Answer 1

0

After quite some search I found the solution on a c# related topic (I use Java, so I missed that one).

Modified my code to this:

        searchForLookUpResult(itemName);
        clickOnLookUpSearchButton();
        driver.findElement(By.xpath("//option[normalize-space(translate(., '\u00A0', ' '))='" + itemName + "']")).click();
        clickDialogOk();
        if (frameContext.equals("Internal")) { switchToFrameManually(1); }
        else switchToDialogFrame();

Apparently the normalize-space in coordination with the translate, did the trick and the element was uniquely identified.

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.