-3

Need some help on Xpath for following code:

<span class-"metadata-row float-left" style="width: 1.9vw;"> &absp; </span>
<input placeholder="New Course Name" id="newCourseName" type="text” class="metadata-name metadata-name-edit font-12" autofocus>
<span class="fa fa-check metadata-action-icon" title="Save" onclick="addCourse(this)" style="display: block;"> ... </span>

I want to click on "Save" which is mentioned as title in the code but in ui it is showing as icon.

Evgeniy Chiruk
  • 358
  • 1
  • 10

2 Answers2

1

To click() on the element with title attribute as Save you need to use elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("span.fa.fa-check.metadata-action-icon[title='Save']"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class='fa fa-check metadata-action-icon' and @title='Save']"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • "Thanks", i have tried the first one but getting exception Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.cssSelector: span.fa.fa-check.metadata-ok.metadata-action-icon[title='Save'] (tried for 20 second(s) with 500 milliseconds interval) – vir softech Jan 21 '20 at 08:34
  • @virsoftech Seems you have replaced the html image with text based HTML and the DOM is changed. I have updated the answer accordingly. – undetected Selenium Jan 21 '20 at 08:41
  • sir i am getting : Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.xpath: //span[@class='fa fa-check metadata-action-icon' and @title='Save'] (tried for 5 second(s) with 500 milliseconds interval) at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:95) at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:272) at test.Utils.saveIcon(Utils.java:51) at test.AdminHomePage.questionWindow(AdminHomePage.java:144) at test.MyClass.main(MyClass.java:59) – vir softech Jan 21 '20 at 08:55
0

try javascript executor

((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);