我试图在Selenium的弹出窗口中点击“是”按钮而无法执行此操作。 HTML代码是:
dplyr
我正在尝试执行的Java代码:
debug(FindRetailer)
FindRetailer<-function(Purchase){
P <- toupper(Purchase)
for(z in 1:length(RetailerNames)){
Retailer<-toupper(RetailerNames[z])
HasFound=grepl(Retailer,P)
if(HasFound==TRUE){
return(str_to_title(Retailer))
}
}
return("Donno")
}
Statement <- data.frame(
Purchase = c("abc Aldi xyz","a Kmart bcd","a STARBUCKS ghju","abcd MacD efg"),
Amount = c(235,23,789,45))
RetailerNames<- c("Aldi","Kmart","Starbucks","MacD")
# what I need
Result <- data.frame(
Purchase = c("abc Aldi xyz","a KMART bcd","a STARBUCKS mmm","abcd MACD efg"),
Amount = c(235,23,789,45),
Retailer = c("Aldi","Kmart","Starbucks","Macd"))
# this works using custom function
NewStatment<-Statement %>%
rowwise() %>%
mutate(Retailer=FindRetailer(Purchase))
# is this possible: join dataframes using complex string matching?
# this doesn't work yet
TestMethod<-Statement %>%
left_join(RetailerNames,by="Statement.Purchase %in% RetailerNames")
它只是跳过步骤而没有实际给出任何错误。
答案 0 :(得分:0)
当您尝试单击“是”按钮时,此xpath可能会帮助您:
driver.findElement(By.xpath(//*[@id="dialoguebuttons"]/a[text()='Yes')).click();
如果这有助于您,请告诉我。
答案 1 :(得分:0)
如果您使用的是firefox浏览器,请安装firebug
Addon和firepath
Addon并使用firepath检查该元素,并在此处粘贴以下代码中提到的双引号之间的xpath:
driver.findElement(By.xpath(" ")).click();
如果您不熟悉firebug
,请参阅this 链接并尝试使用。它会帮助你。