Im試圖實現對錶中元素的點擊。此刻即時搜索表中的特定字符串。如果字符串匹配,我將元素返回給它的調用方法,並嘗試實現點擊,但調用方法從不單擊該元素。Selenium does not implement點擊
任何幫助,將不勝感激。
檢查表的方法。
public static WebElement chk_TableContentsByXpath(String searchString, String elements){
WebElement element = null;
try{
// Grab the table
WebElement table = driver.findElement(By.xpath(elements));
// Now get all the TR elements from the table
List<WebElement> allRows = table.findElements(By.tagName("tr"));
// And iterate over them, getting the cells
for (WebElement row : allRows) {
List<WebElement> cells = row.findElements(By.xpath("./*"));
for (WebElement cell : cells) {
// System.out.println(cell.getText());
if(cell.getText().equals(searchString)){
element = cell;
return element;
}
}
}
}catch (Exception e){
Log.error("Class Utils | Method GetTableContents | Exception occured while search table : "+e.getMessage());
throw (e);
}
return element;
}
調用方法
package appModules;
import pageObjects.MC_Page_links;
import pageObjects.MC_ProductTypes_Page;
import pageObjects.TopNav_links;
import utility.Constant;
import utility.Utils;
public class MC_MaterialProductType_UpdateProductType_Action {
public static void Execute(int iTestCaseRow) throws Exception{
Utils.waitForElement(TopNav_links.lnk_MasterControl());
TopNav_links.lnk_MasterControl().click();
MC_Page_links.lnk_ProductTypes();
Utils.chk_TableContentsByXpath(Constant.MC_ProductTypeName,Constant.MC_ProductTypesTable).click();//this line doesnt implement the click
MC_ProductTypes_Page.inpt_UpdateProductName().sendKeys(Constant.MC_ProductTypeNameUpdate);
}
}