在我的应用程序中,我可以通过单击工具栏中的 2 个不同菜单项来打开两个片段,如以下代码所示:
#find Amazonas xpath
amazonas <- remDr$findElements("xpath", "/html/body/div[2]/div[7]/div[1]/div[4]/div[1]/table/tbody/tr[1]/td[2]/a")
#convert to text
sapply(amazonas, function(x) x$getElementText()) #is Amazonas
#find its location
loc <- amazonas[[1]]$getElementLocation()
loc[c('x','y')]
#click on it
remDr$mouseMoveToLocation(webElement = amazonas[[1]]) # move mouse to the element we selected
remDr$click(1) # 1 indicates click the right mouse button
#individual components of amazonas first dataframe
cell1 <- remDr$findElements(using = 'xpath', value = '//*[@id="vad-table"]/tbody/tr[1]/td[2]')
cell1 <- unlist(sapply(cell1, function(x) x$getElementText())) #Finanzas
#has td[2]
cell2 <- remDr$findElements(using = 'xpath', value = '//*[@id="vad-table"]/tbody/tr[1]/td[3]')
cell2 <- unlist(sapply(cell2, function(x) x$getElementText())) #3
#has td[3]
cell3 <- remDr$findElements(using = 'xpath', value = '//*[@id="vad-table"]/tbody/tr[2]/td[2]')
cell3 <- unlist(sapply(cell3, function(x) x$getElementText())) #Ciencias naturales, aplicadas y relacionadas
#has td[2]
cell4 <- remDr$findElements(using = 'xpath', value = '//*[@id="vad-table"]/tbody/tr[2]/td[3]')
cell4 <- unlist(sapply(cell4, function(x) x$getElementText())) #2
#has td[3]
#make dataframe of individual cells
因此,当我在 UserInfoFragment 中时,我隐藏了打开此片段的图标。当我单击搜索图标时,它会导航到 SearchFragment,然后我无法再次单击该图标以导航到 UserInfoFragment。问题是如果我一直点击菜单项,这两个片段都会被多次添加到返回堆栈中。
我的问题是:如何防止多次添加片段?或:如何检查片段是否已存在于(导航)后台堆栈中?
感谢您的每一个回答。提前谢谢您!