Reputation: 1863
We're using this components in our web application.
On the page you can see a toolbar containing some buttons. If you click on any of the buttons it writes a log into the logbar.
The problem is I cannot record this behavior using the Selenium IDE. The IDE creates a command, but when I execute the command nothing happens. Not even an error is logged.
What could be the problem?
Upvotes: 2
Views: 12075
Reputation: 1
it will take more than 1ms for javascript work . So just add like 'pause 1000'
Upvotes: -2
Reputation: 39
I don't know this will help but it surely helped me
if there is any text you have to type and then click on any element or button
There are two ways
First use "sendKeys
" to type then "click" the required element will work.
For Eg In flipkart.com
"type" doesn't work but "sendKeys
" does
Second is
Use "type" then press enter instead of click using "sendKeys" in target have the field that you were typing and in value must have "${KEY_ENTER}
"
Eg will help you better
First Method:
Second Method:
Both Worked for me fortunately
Upvotes: 1
Reputation: 37826
I visited the site http://www.dhtmlx.com/docs/products/dhtmlxToolbar/samples/01_init/08_events.html
I got the xpath by using xpath checker as below:
Cut - id('toolbarObj')/x:div[5]/x:div[11]/x:div
Copy - id('toolbarObj')/x:div[5]/x:div[12]/x:div
Paste - id('toolbarObj')/x:div[5]/x:div[13]/x:div
You can use the modified xpath as:
selenium.click("//div[@id='toolbarObj']/div[5]/div[11]/div");//Cut
selenium.click("//div[@id='toolbarObj']/div[5]/div[12]/div");//Copy
selenium.click("//div[@id='toolbarObj']/div[5]/div[13]/div");//Paste
Upvotes: 1
Reputation: 37826
Here is the full code of doing that:
package riponalwasim.selenium.webdriver.stackoverflow;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class CutCopyPaste {
WebDriver driver;
String baseUrl;
@BeforeClass
public void setUp() throws Exception {
baseUrl = "http://www.dhtmlx.com/docs/products/dhtmlxToolbar/samples/01_init/08_events.html";
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get(baseUrl);
}
@Test
public void testCutCopyPaste() throws Exception {
driver.findElement(By.xpath("//div[text()='New']")).click();
driver.findElement(By.xpath("//div[@id='toolbarObj']/div[5]/div[11]/div")).click();
driver.findElement(By.xpath("//div[@id='toolbarObj']/div[5]/div[12]/div")).click();
driver.findElement(By.xpath("//div[@id='toolbarObj']/div[5]/div[13]/div")).click();
}
@AfterClass
public void tearDown() throws Exception {
driver.quit();
}
}
Upvotes: 0
Reputation: 36
The IDE isn't perfect at recording when javascript has loaded items to the page, so it may need manual assistance.
Have you tried waiting for the element to load before trying to click on it? I might suggest inserting a waitForElementPresent command, like waitForElementPresent | #toolbarObj before trying the click.
Upvotes: 0
Reputation: 25076
What about if you click on the img itself instead of the div? E.g:
//img[contains(@src, 'paste')]
When you click on 'Find' on the Selenium IDE, does it actually highlight something on the page?
Upvotes: 0
Reputation: 2002
Execute your script at slow speed
Use xpath to identify element like
clickAt | //div[text()='New']
To click New button
Upvotes: 3
Reputation: 12916
It could be that the selenium script starts too fast. I guess the component you're using generates a bunch of HTML for all the buttons. If the script starts too early the html might not have been generated yet. Try running the selenium script slower.
Also: I think selenium uses XPath to get to the HTML elements in the page. Are you sure that the selenium script is referring to the correct HTML node? You can check this by looking at the selenium script (it's XML) and look what XPath selector it uses for the button.
What also could be the case is that selenium might not be able to fire click events on non clickable targets (the buttons are divs), but I don't think that is the case. You could try though.
Upvotes: 0