简体   繁体   中英

Salesforce custom objects accessing using selenium webdriver with java

Each time SalesForce does a new release, most of the ID's of the elements on the salesforce webpage change(I use the ID property of the element to locate it with my automation code). This breaks my automation scripts.

In my case one text box named as "Question Name" i want to enter a value in this text box.

recent html:

<label class="label inputLabel uiLabel-left form-element__label uiLabel" for="7:1781;a" data-aura-rendered-by="1040:0" data-aura-class="uiLabel">
<span class="" data-aura-rendered-by="1041:0">Question Name</span>
<span class="required " data-aura-rendered-by="8:1781;a">*</span>
</label>
<input id="7:1781;a" class=" input" maxlength="80" aria-describedby="" placeholder="" required="" data-aura-rendered-by="11:1781;a" 
data-interactive-lib-uid="5" aria-required="true" type="text">

my existing xpath :

driver.findElement(By.xpath("//input[@id='6:2634;a']")).sendKeys("test");

Salesforce application all ID's are dynamically changed for every new release, my test script failed with the above xpath with Id, so please suggest me alternate solution.

how should i get the input id value in runtime? or let me know is there any other possible.

You can use the following:

driver.findElement(By.xpath("//label[contains(., 'Question Name')]/following-sibling::input")).sendKeys("test");

This will search for a label containing the text 'Question Name' and then selects the following input sibling

要在名为"Question Name"的文本框中输入值,可以使用以下代码行:

driver.findElement(By.xpath("//label[@class='label inputLabel uiLabel-left form-element__label uiLabel']/span[text()='Question Name']//following::input")).sendKeys("test");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM