我是Salesforce的新手。我正在尝试在Salesforce页面(闪电体验)中进行自动化。我现在正在工作的页面具有以下设计,
如何将驱动程序实例传递给同一页面的当前显示子选项卡?
目前,当我尝试访问新打开的子选项卡的页面元素时,由于驱动程序仍保持在第一个打开的选项卡并获取其元素的情况下,它引发了异常。
答案 0 :(得分:0)
您必须从搜索类返回SearchResultTab类对象,该对象将初始化子选项卡的元素。尝试下面的代码。请阅读在Search类中写有注释的代码。
public class Search {
private WebDriver driver;
@FindBy(css=".LM6RPg")
private WebElement searchTextBox;
@FindBy(css = ".vh79eN")
private WebElement searchButton;
public Search(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver, this);
}
// A method which initializes tab page on submitting search page
public SearchResults searchInStore(String query) {
searchTextBox.sendKeys(query + Keys.SPACE);
searchButton.click();
return new SearchTab(driver, query);
}
}
public class SearchTab {
@FindBy(css="._1ZODb3")
public WebElement tabElement1;
@FindBy(how = How.XPATH, using = "//div[@class='_3wU53n']")
public List<WebElement> tabElement2;
public SearchResults(WebDriver driver, String query) {
this.driver = driver;
PageFactory.initElements(driver, this);
wait = new WebDriverWait(this.driver,2000);
}
}
public class SearchTabTest{
@Test
public void testProductSearch() {
Search search = new Search(Browser.driver);
SearchResults searchResults = search.Search().searchInStore("iphone 5s");
searchResults.tabElement1.getText();
searchResults.tabElement2.getText();
}
}
public class Browser {
private static WebDriver driver;
public static WebDriver driver() {
System.setProperty("webdriver.chrome.driver", "./resources/browserdrivers/chromedriver.exe");
DesiredCapabilities caps = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions");
caps.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(caps);
driver.manage().window().maximize();
return driver;
}
public static void open(String url) {
driver.get(url);
}
public static void close() {
driver.quit();
}
}