无法读取未定义的属性“defaultView”

问题描述 投票:0回答:6
selenium
6个回答
3
投票

尝试单击其父代/祖先。例如,如果您有

//a[text()='link of your text']

并且您收到 javascript 错误,请尝试:

//a[text()='link of your text']/parent::*

3
投票

尝试以下代码 - 它适用于 Salesforce Lightning UI 屏幕:

      WebElement element = driver.findElement(By.xpath("your xpath"));
      JavascriptExecutor executor = (JavascriptExecutor)driver;
      executor.executeScript("arguments[0].click();", element);

测试后发现可以用,分享一下。


2
投票

要单击以下链接,请使用

WebDriverWait
elementToBeClickable
,然后使用以下 xpath 单击该链接。

WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@title='Country']/span[@class='slds-truncate'][contains(.,'Country')]"))).click();

0
投票

对于那些尝试使用 Python 的人,您可以这样做:

>>> button_link = driver.find_element_by_xpath('''//*[@id="tab-23"]/slot''')
>>> driver.execute_script("arguments[0].click();", button_link )

0
投票

尝试 JavaScript。它对我有用

WebElement element = driver.findElement(By.xpath("strPath"));
((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);

0
投票

使用 SalesForce,我必须选择两个更高的父级别,单击

one-app-nav-bar-item-root
,而不是锚标记,这一开始并不直观。

要单击我的帐户选项卡,我使用了

//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();
}
© www.soinside.com 2019 - 2024. All rights reserved.