1

The HTML is as follows:

<div id="button-1600" class="x-btn x-box-item x-toolbar-item x-btn-    default-small x-noicon x-btn-noicon x-btn-default-small-noicon" style="border-width: 1px; left: 109px; margin: 0px; top: 0px;">
<em id="button-1600-btnWrap">
<button id="button-1600-btnEl" class="x-btn-center" autocomplete="off" role="button" hidefocus="true" type="button" style="height: 14px;">
<span id="button-1600-btnInnerEl" class="x-btn-inner" style="">QA View</span>
<span id="button-1600-btnIconEl" class="x-btn-icon "></span>
</button>

I need to select the button "QA View". Since our software uses extJS, the ID # (1600) changes everytime the page is loaded. I tried using the long xpath such as follows:

DP_DEALER_SEARCH_QA_VIEW = 'html/body/div[1]/div[3]/div/div/div[2]/div/div/div/div/div/div[2]/em/button'

def click_dealerSearchQAView(self):
    webQABtn = WebDriverWait(self.driver, 10).until(
        ec.element_to_be_clickable((By.XPATH, DP_DEALER_SEARCH_QA_VIEW)))
    webQABtn.click()

I know there are ways to find this element using the shorter XPath method and things such as [Contains], but I haven't been able to figure it out. Any help is greatly appreciated.

1 Answer 1

2

You can select it by text:

//button[. = "QA View"]

Or, to an additional parent check:

//div[starts-with(@id, "button-")]//button[. = "QA View"]
Sign up to request clarification or add additional context in comments.

1 Comment

I was able to select it by the text, which is VERY useful. I will probably incorporate the parent check in the long run. It won't let me mark your answer yet, but it worked. Thank you!

Your Answer

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.