0

I have an element on the web page that has random generated id eg: id=8726dd92-7bdf-4435-bf75-653859329c06. Now how do I go about writing the xpath for the same?

There were other attributes like aria-label and class but none of them seemed to work. I have tried using most of the available xpath generators to capture that element but no success. Right click -> inspect generated //*[@id="8726dd92-7bdf-4435-bf75-653859329c06"] which is not unique and keeps changing for every page load

This is the tag available for the element:

<input aria-required="true" aria-label="Name" id="8726dd92-7bdf-4435-bf75-653859329c06" class="rwa-input fixed " maxlength="100">

I want to have a function that can capture the dynamic value during run time and replace the variable on my xpath. Eg: //*[@id='dynamic-id'].

DOM-Structure

  • Can you try with `//input[@class='rwa-input fixed'][@aria-label='Name']`. Then you can use `get_attribute('id')` to get the dynamic id if you want to use it somewhere else. – supputuri Jul 23 '19 at 19:45
  • Looks like my elements are inside "#shadow-root" . Is there any way to find them using an xpath ? – Dorothy Judy Jul 28 '19 at 19:48
  • Yes. Check this [url](https://stackoverflow.com/questions/56380091/how-to-interact-with-the-elements-within-shadow-root-open-while-clearing-brow/56381495#56381495) which will give the detailed explanation on how to work with shadow-root tree. And let me know if you need any help on this, I can provide the code if required. – supputuri Jul 29 '19 at 02:35

1 Answers1

0

If class name is unique than u can try below xpath

driver.findElement(By.xpath("//input[@class='rwa-input fixed ']"));
mk_
  • 164
  • 1
  • 14