简体   繁体   English

如何识别Salesforce Lightning for Selenium中的元素

[英]How to Identify Elements in Salesforce Lightning for Selenium

I am trying to automate Salesforce lightning using Selenium, but getting issues with identifying elements. 我正在尝试使用Selenium自动化Salesforce闪电,但是在识别元素方面遇到问题。 Reason, its having dynamic IDs , and other attributes are either very long , or they are not unique. 原因,具有动态ID的原因以及其他属性要么很长,要么不是唯一的。

For eg , 例如,

<a id="170:1968;a" class="textUnderline outputLookupLink slds-truncate forceOutputLookup" 
data-refid="recordId" 
data-recordid="0059E000001aOCSQA2" 
data-special-link="true" 
href="#/sObject/0059E000001aOCSQA2/view" 
target="_blank" rel="noreferrer" 
title="" data-aura-rendered-by="170:1968;a" data-aura-class="forceOutputLookup"/>

In above code , ID is dynamic , Class is not unique, and all the Lookup elements are associated with it. 在上面的代码中,ID是动态的,Class不是唯一的,并且所有Lookup元素都与之关联。 Also the absolute path is not much trusted , and hence I am trying to find any concrete option to handle these elements. 另外,绝对路径不是很受信任,因此我试图找到任何处理这些元素的具体选择。 Any help will be highly appreciated. 任何帮助将不胜感激。

Here, you could try using the contains method if at least a part of the id attribute value is static. 在这里,如果id属性值的至少一部分是静态的,则可以尝试使用contains方法。 From your code, you could try 从您的代码中,您可以尝试

//a[contains(@id,"a")]/ //--extended xpath--

From the given html code, the 'a' in the id attribute of the a tag looks static, while the rest changes. 从给定的html代码中, a标签的id属性中的'a'看起来是静态的,而其余的都改变了。

您可以要求开发人员使用aura:id向闪电组件提供ID,这样就不会生成动态ID。

You can try with field labels and fetch its parent node(s), and then fetching childs or brother nodes to locate related texts/text boxes etc. 您可以尝试使用字段标签并获取其父节点,然后获取子节点或兄弟节点以找到相关的文本/文本框等。

Eg. 例如。 You are in Account Edit/New page, and you want to fill in a value to the text box for Account Name field. 您在“帐户编辑/新建”页面中,并且想要在“帐户名称”字段的文本框中填写一个值。 So you can firstly try with //*[text()='Account Name']/parent::* to find an element that covers BOTH the field label and the text box. 所以,你可以首先与尝试//*[text()='Account Name']/parent::*找到一个涵盖字段标签和文本框的元素。

And then you can check if the text box is a 'brother' or a 'child'. 然后,您可以检查文本框是“兄弟”还是“孩子”。 If it's a 'child' then try with //*[text()='Account Name']/parent::*(/parent::*)//*[attributes for the text box] ; 如果是“孩子”,则尝试使用//*[text()='Account Name']/parent::*(/parent::*)//*[attributes for the text box] If it's 'brothers' then try with //*[text()='Account Name']/parent::*(/parent::*)/following-sibling::*[attributes for the text box] 如果是“兄弟”,则尝试使用//*[text()='Account Name']/parent::*(/parent::*)/following-sibling::*[attributes for the text box]

You can use this logic to locate all type of fields in all standard lightning pages. 您可以使用此逻辑在所有标准闪电页面中找到所有类型的字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Salesforce Lightning / Z9E13B69D1D2DA927102ACAAAF7154A3 上使用 Selenium 和 Java - Using Selenium with Java on Salesforce Lightning / Javascript problems 在元素的子选项卡中时如何获取元素的XPath(Salesforce Lightning组件) - How to get XPath of an element when it is in sub tab (Salesforce Lightning component) 如何通过 Selenium 中的 DOM 属性识别元素? - How do I identify elements by DOM attributes in Selenium? Ruby Selenium-如何在运行时基于属性识别元素 - Ruby Selenium - How to identify elements based on attributes at runtime 如何在TestNG中使用Selenium Webdriver使用text属性标识元素 - How to identify Elements using text attribute by Selenium Webdriver in TestNG Selenium Web Driver_如何识别canvas map中的web元素 - Selenium Web Driver _ How to Identify web elements in canvas map 如何使用 Selenium 和 VBA 识别包含特殊字符的元素类名 - How to identify elements classname containing special characters using Selenium and VBA 在下面的Expedia网站示例中,如何使用硒唯一标识元素 - How to uniquely identify elements with selenium for below Expedia site example 无法找到Salesforce Lightning的元素 - Unable to Locate an element for Salesforce Lightning 如何处理 Selenium 中的 Salesforce 悬停 - how to handle salesforce hover in selenium
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM