I got web application, i can login and see a table of transactions. There is icon, i am trying to use webdriver to retrieve icon, i fail to get the icon.
how to click the delete icon and action triggers?
String baseURL = "http://testingapp.workspez.com/login";
driver.get(baseURL);
driver.findElement(By.xpath("//input[@id='field_email']")).sendKeys("rahul@workspez.com");
driver.findElement(By.xpath("//input[@id='field_password']")).sendKeys("Sujeet@19");
driver.findElement(By.className("MuiButton-label")).click();
WebElement generalInfo = driver.findElement(By.xpath("//*[text()='General Info']"));
generalInfo.click();
WebElement md = driver.findElement(By.xpath("//*[text()='Contacts']"));
md.click();
WebElement searchbox = driver.findElement(By.xpath("//input[@class='MuiInputBase-input MuiInput-input']"));
searchbox.sendKeys("fat1");
WebElement search = driver.findElement(By.xpath(".//*[@class='MuiButtonBase-root MuiIconButton-root']"));
search.click();
List<WebElement> menulist = driver.findElements(By.xpath(".//*[@class='MuiButtonBase-root MuiIconButton-root']"));
System.out.println(menulist.size());
menulist.get(3).click();
WebElement deleteicon = driver.findElement(By.xpath("//ul[@class='MuiList-root MuiMenu-list MuiList-padding']"));
deleteicon.click();
To click on the svg enabled Delete
icon you need to use WebDriverWait for the elementToBeClickable()
and you can use the following xpath based Locator Strategies :
import java.util.Collections;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class ElementToBeClickable {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\\\WebDrivers\\\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
options.setExperimentalOption("useAutomationExtension", false);
WebDriver driver = new ChromeDriver(options);
driver.get("http://testingapp.workspez.com/login");
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='field_email']"))).sendKeys("rahul@workspez.com");
driver.findElement(By.xpath("//input[@id='field_password']")).sendKeys("Sujeet@19");
driver.findElement(By.xpath("//span[@class='MuiButton-label' and contains(., 'Log In')]")).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class='MuiButton-label' and contains(., 'General Info')]"))).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='MuiInputBase-input MuiInput-input']"))).sendKeys("aa");
driver.findElement(By.xpath("//button[@class='MuiButtonBase-root MuiIconButton-root' and @title='Search']")).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//td[@class='MuiTableCell-root MuiTableCell-body']//button[@class='MuiButtonBase-root MuiIconButton-root']/span[@class='MuiIconButton-label']"))).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//li[@class='MuiButtonBase-root MuiListItem-root MuiMenuItem-root MuiMenuItem-gutters MuiListItem-gutters MuiListItem-button']/*[name()='svg']"))).click();
}
}
Browser Snapshot:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.