Selenium2 / WebDriver: How to click an <i> element in an <a> element?



  • I got stuck for the below code.it has an edit icon for which code are follows: <a href="#tradeModal" id="tradeModalEdit" data-toggle="modal" class="pull-right" style="margin-left: 12px;" title="Edit trade" onclick="return populateTradeTicketSectionEdit(); ClearTradeModal();"><i class="icon-edit"></i></a> This is the one for which i coded in selenium : driver.findElement(By.xpath("//a[@href='#tradeModal'and contains(@id,'tradeModalEdit')]/i[@class='icon-edit']")).click(); when i click on save by using below code: WebElement saveEditTrade = driver.findElement(By.xpath("//a[@href='#' and contains(@onclick,'return SaveTradeDetails();')]")); //code for saving the details in edit trade pop up// saveEditTrade.click(); this works fine but point is when i am clicking on consecutive window edit icon like below: <a href="#feeModal" data-toggle="modal" class="pull-right" style="margin-left: 12px;" title="Edit fee" onclick=" return clearFeeModal();"><i class="icon-edit"></i></a> selenium code: driver.findElement(By.xpath("//a[@href='#feeModal'and contains(@onclick,'clearFeeModal();')]/i[@class='icon-edit']")).click();//code for saving the details in Edit Fee pop up it has other input fields dats okies but my point is execution fails bcuz its showing element is not visible for last edit code that i posted just above line.i can see when data are populating for saving for 1st code at the same time 2nd edit code pops up eventhough i put implicit wait commands or i tried with expected conditions wait. Please advise.



  • Why didn't you code your locator like this? driver.findElement(By.xpath(".//a/i[@class='icon-edit']")).click(); Seems like it would have still worked and would have been simpler.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2