[英]How to Locate a DYNAMIC Salesforce Lightning INPUT Element with XPATH using C# in Selenium WebDriver
I need to find out how to Locate a Dynamic Salesforce Lightning Input Element with XPATH using C# in Selenium WebDriver.我需要了解如何在 Selenium WebDriver 中使用 C# 使用 XPATH 定位动态 Salesforce Lightning 输入元素。 I just can't get it to work.
我只是无法让它工作。 Below is the code I've tried followed by the HTML and Full XPATH.
下面是我尝试过的代码,然后是 HTML 和完整的 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?
我收到错误令牌错误,不知道这意味着什么。`有人可以告诉我更好的方法,例如 Parent:Child locate 吗? These Lightning Elements are a tough nut to crack...Thanks in Advance!
这些闪电元素很难破解……提前致谢!
C# Selenium WebDriver Code: C# Selenium WebDriver 代码:
//CODE FAILS! //Enter File Number/SSN/TIN ID and Click Search
**driver.FindElement(By.XPath("//input[starts-with(@id.'input-')]")).Click();
HTML: 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="">
FULL XPATH: /html/body/div[4]/div[1]/div[2]/div[1]/div/div/div/div/div/div/div[2]/div/div[1]/div/div[1]/cempw-r_-participant-search/article/div[2]/lightning-input/div/input
完整 XPATH:
/html/body/div[4]/div[1]/div[2]/div[1]/div/div/div/div/div/div/div[2]/div/div[1]/div/div[1]/cempw-r_-participant-search/article/div[2]/lightning-input/div/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-'"}
{"由于以下错误,无法使用 xpath 表达式 //input[starts-with(@id.'input-')] 定位元素:\\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() driver.FindElement(By.XPath(".//input[starts-with(@id.'input-')]")).Click()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.