我正在使用 Robot Framework 和 Selenium 对 Salesforce 应用程序进行自动化测试。我编写了一个测试用例脚本来登录 Salesforce、导航到“机会”页面并执行 JavaScript 代码片段以与页面上的元素进行交互。但是,我在执行脚本期间遇到错误。这是我的脚本的简化版本:
*** Settings ***
Library SeleniumLibrary
Library Dialogs
Library Telnet
*** Variables ***
${URL} https://mycompany.lightning.force.com/lightning/page/home
${BROWSER} Chrome
${USERNAME} ****
${PASSWORD} ****
${element} xpath://a[@title='Opportunities']
${chrome_options} add_argument("--incognito")
*** Test Cases ***
Open Salesforce Login Page
${chrome_options} Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
Call Method ${chrome_options} add_argument --incognito
Open Browser ${URL} ${BROWSER} options=${chrome_options}
Title Should Be Login | Salesforce
Wait Until Page Contains Username
Input Text id:username ${USERNAME}
Input Text id:password ${PASSWORD}
Click Button id:Login
Wait Until Page Contains Opportunities
Opportunity Creation
Wait Until Page Contains Element xpath://a[@title='Opportunities'] timeout=10s
Execute Javascript document.querySelector("a[title='Opportunities']").click();
当我运行此脚本时,它在执行 Javascript 步骤失败,并出现以下错误:
Opportunity Creation | FAIL |
JavascriptException: Message: javascript error: Cannot read properties of null (reading 'click')
(Session info: chrome=118.0.5993.118)
Stacktrace:
GetHandleVerifier [0x00007FF646798EF2+54786]
(No symbol) [0x00007FF646705612]
(No symbol) [0x00007FF6465BA64B]
(No symbol) [0x00007FF6465BF116]
(No symbol) [0x00007FF6465C14AA]
(No symbol) [0x00007FF646635394]
(No symbol) [0x00007FF64661BE6A]
(No symbol) [0x00007FF646634D02]
(No symbol) [0x00007FF64661BC43]
(No symbol) [0x00007FF6465F0941]
(No symbol) [0x00007FF6465F1B84]
GetHandleVerifier [0x00007FF646AE7F52+3524194]
GetHandleVerifier [0x00007FF646B3D800+3874576]
GetHandleVerifier [0x00007FF646B35D7F+3843215]
GetHandleVerifier [0x00007FF646835086+694166]
(No symbol) [0x00007FF646710A88]
(No symbol) [0x00007FF64670CA94]
(No symbol) [0x00007FF64670CBC2]
(No symbol) [0x00007FF6466FCC83]
(No symbol) [0x00007FFDC169257D]
RtlUserThreadStart [0x00007FFDC2FEAA78+40]
我已经验证了 XPath 定位器和 JavaScript 片段,两者似乎都是正确的。我还尝试增加页面加载的超时时间,但错误仍然存在。
我觉得总的来说,我在使用 Salesforce 测试框架时遇到了问题。 有没有人遇到过类似的问题或对如何解决这个问题有任何建议?预先感谢您的帮助!
使用 SalesForce,我必须选择两个高于预期的父级别,单击
one-app-nav-bar-item-root
而不是锚标记。
要单击我的帐户选项卡,我使用了 xPath
//one-app-nav-bar-item-root/a/span[text()='Accounts']/parent::*/parent::*
,然后应用了单击。
/**
* <p>This method will navigate to a tab open in the top of SalesForce using the tabs name.</p>
* @param tabName The text displayed on the tab. Not a URL.
* @author <a href="https://stackoverflow.com/users/9889584/sjb">Shawn J Burke</a>
*/
public void navigateOneAppBarItem(String tabName) {
String xPath = String.format("//one-app-nav-bar-item-root/a/span[text()='%s']/parent::*/parent::*", tabName);
System.out.println(xPath);
WebElement oneBarTab = this.getWebDriver().findElement(By.ByName.xpath(xPath));
oneBarTab.click();
}