Hey,
I'm in a situation where I need to use XPATH when selecting elements
for my web application. The elements all have dynamic ids, and XPATH
currently is the only solution I've found. My dilemia is there are
a lot of IFRAMES setup in the application I'm testing. I've been
told that I need to select the iframe first, before clicking on an
element that is further down the DOM tree.
My code looks like
public static void main(String[] args) //throws IOException
{
final String sBaseUrl = "
http://oberon/";
//DefaultSelenium oDefaultSelenium = new
DefaultSelenium(sServerHost, iServerPort, sBrowserType, sBaseUrl);
//For WebDriver
WebDriver iedriver = new InternetExplorerDriver();
DefaultSelenium oDefaultSelenium = new
WebDriverBackedSelenium(iedriver,sBaseUrl);
WebDriver driver = ((WrapsDriver)
oDefaultSelenium).getWrappedDriver();
oDefaultSelenium.open("
http://oberon/BullhornStaffing/
BHlogin.cfm");
oDefaultSelenium.type("username", "ddonathan");
oDefaultSelenium.type("password", "0");
oDefaultSelenium.click("//input[@value='Login']");
boolean bLoopAgain = true;
int iLoopCount = 0;
WebElement element = driver.findElement(By.xpath("//
table[@id='bhMenuContainer']/tbody/tr/td/div/div/table/tbody/tr/td"));
element.click();
Common.threadsleep(5000);
//Activity Center
driver.findElement(By.xpath("//table[@id='bhMenuContainer']/tbody/tr/
td/div/div[2]/div[2]/table/tbody/tr[7]/td[2]")).click();
String sTitle = oDefaultSelenium.getText("id=bh_root");
while (bLoopAgain) {
if (sTitle.indexOf("Activity Center")>=0){
System.out.println("In Activity Center");
//Test AC item expansion
//first AC e-mail
Common.threadsleep(5000);
//oDefaultSelenium.selectWindow("");
//
********Problem area **************************
oDefaultSelenium.selectFrame("index=1");
//
******************************************
//This allows me to click on the record itself!
oDefaultSelenium.clickAt("//html/body/div/div", "1,1");
Throws the following:
Exception in thread "main"
com.thoughtworks.selenium.SeleniumException: No frame found (WARNING:
The server did not provide any stacktrace information); duration or
timeout: 51 milliseconds
Build info: version: '2.6.0', revision: '13840', time: '2011-09-13
14:56:25'
System info:
os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1',
java.version: '1.6.0_16'
Driver info: driver.version: RemoteWebDriver
at
org.openqa.selenium.internal.seleniumemulation.Windows.selectFrame(Windows.java:
85)
at
org.openqa.selenium.internal.seleniumemulation.SelectFrame.handleSeleneseCommand(SelectFrame.java:
31)
at
org.openqa.selenium.internal.seleniumemulation.SelectFrame.handleSeleneseCommand(SelectFrame.java:
1)
at
org.openqa.selenium.internal.seleniumemulation.SeleneseCommand.apply(SeleneseCommand.java:
33)
at
org.openqa.selenium.internal.seleniumemulation.Timer.run(Timer.java:
39)
at
org.openqa.selenium.WebDriverCommandProcessor.execute(WebDriverCommandProcessor.java:
265)
at
org.openqa.selenium.WebDriverCommandProcessor.doCommand(WebDriverCommandProcessor.java:
195)
at
com.thoughtworks.selenium.DefaultSelenium.selectFrame(DefaultSelenium.java:
382)
at BHTester.Activity_Center.AC_Verification(Activity_Center.java:234)
at BHTester.mainSanityTest.main(mainSanityTest.java:39)
When I use MS: Developer tools, or Debug bar, I see the IFRAME (There
are two of them). I'm selecting an index of 1 since it is the 2nd
frame I want.
If I try the selectFrame code using Selenium RC1, I get no error
(However, I'm still unable to click on the element).
Any ideas?