Home > Software design >  unique xpath combined two attributes
unique xpath combined two attributes

Time:11-12

Ho do I make unique xpath to let the robot locate into second field?

i used this but failed:

Click     //div[contains(@class,'ant-select SearchPrompter_advInput__3P9Jf ant-select-multiple ant-select-allow-clear ant-select-show-search') and contains(text(),'Select Source(s)')]

First Field:

<div class="ant-select SearchPrompter_advInput__3P9Jf ant-select-multiple ant-select-allow-clear ant-select-show-search">
    <div class="ant-select-selector">
        <div class="ant-select-selection-overflow">
            <div class="ant-select-selection-overflow-item ant-select-selection-overflow-item-suffix" style="opacity: 1;">
                <div class="ant-select-selection-search" style="width: 3px;">
                    <input autocomplete="off" type="search" class="ant-select-selection-search-input" role="combobox" aria-haspopup="listbox" aria-owns="rc_select_9_list" aria-autocomplete="list" aria-controls="rc_select_9_list" aria-activedescendant="rc_select_9_list_7" value="" id="rc_select_9" style="opacity: 0;" aria-expanded="false" readonly="" unselectable="on">
                        <span class="ant-select-selection-search-mirror" aria-hidden="true">&nbsp;</span>
                    </div>
                </div>
            </div>
            <span class="ant-select-selection-placeholder">attribute(s)</span>
        </div>
    </div>

second field:

<div class="ant-select SearchPrompter_advInput__3P9Jf ant-select-multiple ant-select-allow-clear ant-select-show-search">
    <div class="ant-select-selector">
        <div class="ant-select-selection-overflow">
            <div class="ant-select-selection-overflow-item ant-select-selection-overflow-item-suffix" style="opacity: 1;">
                <div class="ant-select-selection-search" style="width: 3px;">
                    <input autocomplete="off" type="search" class="ant-select-selection-search-input" role="combobox" aria-haspopup="listbox" aria-owns="rc_select_10_list" aria-autocomplete="list" aria-controls="rc_select_10_list" aria-activedescendant="rc_select_10_list_0" value="" id="rc_select_10" style="opacity: 0;" aria-expanded="false" readonly="" unselectable="on">
                        <span class="ant-select-selection-search-mirror" aria-hidden="true">&nbsp;</span>
                    </div>
                </div>
            </div>
            <span class="ant-select-selection-placeholder">Select Source(s)</span>
        </div>
    </div>

this xpath works (when I test at chrome developer console, it is detected) but when robot executed the script, it does not really click into the field. the drop-down list does not display.

Click     //div[@]

error:

    FAIL
Message:    TimeoutError: locator.click: Timeout 10000ms exceeded.
=========================== logs ===========================
waiting for selector "//span[contains(@class,'ant-select-selection-placeholder') and contains(text(),'Select Source(s)')] >> nth=0"
  selector resolved to hidden <span class="ant-select-selection-placeholder">Select Source(s)</span>
attempting click action
  waiting for element to be visible, enabled and stable
    element is not stable - waiting...
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  checking that element receives pointer events at (1080.4,304.7)
  <div class="ant-select-selection-overflow"></div> intercepts pointer events
retrying click action, attempt #1
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  checking that element receives pointer events at (1080.4,304.7)
    [ Message content over the limit has been removed. ]
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  checking that element receives pointer events at (1080.4,304.7)
  <div class="ant-select-selection-overflow"></div> intercepts pointer events

CodePudding user response:

you are not so far from solution to select the uniq div

text equals:

//div[contains(@class,'ant-select SearchPrompter_advInput__3P9Jf ant-select-multiple ant-select-allow-clear ant-select-show-search') and .//span[text()='Select Source(s)']]

if you want the expression contains:

//div[contains(@class,'ant-select SearchPrompter_advInput__3P9Jf ant-select-multiple ant-select-allow-clear ant-select-show-search') and .//span[contains(.,'Select Source(s)')]]

CodePudding user response:

You can give an index according to your best match like

(//*[@class='ant-select SearchPrompter_advInput__3P9Jf ant-select-multiple ant-select-allow-clear ant-select-show-search'])[2]

CodePudding user response:

Try to use the span tag and parent keyword in the xpath to find the required div tag element.

As per the HTML Code, Xpath would be something like this.

//span[contains(text(),'Select Source')]/parent::div/parent::div/parent::div
  • Related