Unable to click/select on an image from a frame | Selenium Forum
M
Posted on 08/02/2016
Hi Ashish,

I am not able to click/select an image(There are like 25 images on a toolbar) from a frame. I tired simple click , actions and elementtobeclickable methods but no luck. If you may please help.

Below is the code. Attached are the screen shots of UI with X path and ID i tried to find an element(Highlighted in color).

import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class OrderToolBar {

public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.ie.driver","C:\\IEDriverServer_x64_2.50.0\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();

// launch IE and direct it to the Base URL
String baseUrl = "http://trafficwebrel-qa.devtest.local/OneTimMvc/OrderStatus";
driver.get(baseUrl);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

//Get Title & Switch to Frame
System.out.println(driver.getTitle());

List<WebElement> frames = driver.findElements(By.tagName("iframe"));
System.out.println(frames.size());
driver.switchTo().frame(0);
Thread.sleep(5000);

//Option 1 - Did not work
driver.findElement((By.xpath("//*[@id='OrderToolbar_DXI8_T']"))).click();

//Option 2 - Did not work
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.xpath("//*[@id='OrderToolbar_DXI8_Img']"))).doubleClick().build().perform();

//Option 3 - Did not work
WebDriverWait wait = new WebDriverWait(driver,30);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='OrderToolbar_DXI8_Img']")));
element.click();

//Find total Images - Works
WebElement Box = driver.findElement(By.xpath(".//*[@id='OrderToolbar']"));
List<WebElement> Images = Box.findElements(By.tagName("img"));
System.out.println("Total Images:"+Images.size());

for (int i=0;i<=Images.size();i++){
Box = driver.findElement(By.xpath(".//*[@id='OrderToolbar']"));
Images = Box.findElements(By.tagName("img"));
System.out.println(Images.get(i).getAttribute("title"));
}

}

}

M
Replied on 08/02/2016

have you used actions class with single click.


M
Replied on 09/02/2016

Yes. I just tried. Did not work either. When I do double click, it's clicking somewhere else. Though the Xpath is different for the New(+) toolbar option and where it's clicking.

Please check the document, New_Reply.


M
Replied on 09/02/2016

For (+) Image on the toolbar, if we check the HTML, there are two objects overlapping actually. The box with + image in it and the + image itself. I tried to perform click on both the options by Xpath, ID and Class Name. No luck.

If i get attribute title, it is giving me total 25 images, which is right actually. Not sure why it will not click/select an image then.

<li id="OrderToolbar_DXI8_" class="dxm-item dxm-noSubMenu dxm-hovered" title="New Order" style="min-width: 31px;">
<div id="OrderToolbar_DXI8_T" class="dxm-content ">
<img id="OrderToolbar_DXI8_Img" class="dxm-image dx-vam" alt="" src="/OneTimMvc/Content/Shared/icons/Add.png" title="New Order"/>
</div>
</li>

For better understanding check the attachment.


M
Replied on 09/02/2016

Just realized that the frame keeps changing every time i open up the application. What would be the best way to handle this situation?


M
Replied on 10/02/2016

we have explained frame handling in the videos.


M
Replied on 15/02/2016

idk but i had to use java script executor to get it done.


M
Replied on 15/02/2016

watch module 15.