I need to find out how to Locate a Dynamic Salesforce Lightning Input Element with XPATH using C# in Selenium WebDriver. I just can't get it to work. Below is the code I've tried followed by the HTML and Full XPATH. I get a Bad Token Error and don't know what that means.`Can someone show me a better way like Parent:Child locate? These Lightning Elements are a tough nut to crack...Thanks in Advance!
C# Selenium WebDriver Code:
//CODE FAILS! //Enter File Number/SSN/TIN ID and Click Search
**driver.FindElement(By.XPath("//input[starts-with(@id.'input-')]")).Click();
HTML:
<input name="Participant Id" class="slds-input" id="input-32" aria-describedby="help-message-32" required="" type="text" maxlength="9" pattern="([0-9]*)$" lightning-input_input="">
<div class="slds-form-element__control slds-grow" lightning-input_input=""><input name="Participant Id"
class="slds-input" id="input-32" required="" type="text" maxlength="9" pattern="([0-9]*)$" lightning-
input_input=""></div>
<input name="Participant Id" class="slds-input" id="input-32" required="" type="text" maxlength="9"
pattern="([0-9]*)$" lightning-input_input="">
ERROR :
{"Unable to locate an element with the xpath expression //input[starts-with(@id.'input-')] because of the following error:\\nError: Bad token: 'input-'"}
Try putting a "." before the double slashes, prior to "input" tag name, and use "@" before Attributes:
driver.FindElement(By.XPath(".//input[starts-with(@id.'input-')]")).Click()
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.