不能打电话给Drop down&甚至不能参考当前的网址

时间:2015-08-14 08:41:56

标签: selenium selenium-webdriver selenium-ide

这是我的代码
无法参考下拉列表甚至无法获取网址

代码包含url打开,然后单击菜单,然后打开下拉列表 我既不能打开下拉也不能打开当前网址,请建议

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.gargoylesoftware.htmlunit.javascript.host.svg.SVGTextElement;

public class LoginTest { 
    private WebDriver driver;
    private String baseUrl;

    String[] arr=new String[50];

/*TO open URL*/
@BeforeMethod
public void setUp() throws Exception {
  driver = new FirefoxDriver();
  baseUrl = "http://52.74.254.186:8088/mdmapp/ShowLogin.action?popup=true";
  driver.manage().window().maximize();
  driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

  //UserName & Password creation
 /* for(int i=1;i<=50;i++){
      if(i<=25){
          arr[i-1]="opo."+i;
      }else{
          arr[i-1]="sooksham."+(i-25);
      }
  }*/
}

@Test (priority = 1)
public void testLoginMDM() throws Exception {
    //captures the dynamic url like popup


/*for(int i=0;i<arr.length;i++)*/{  
  driver.get(baseUrl + "/mdmapp/ShowLogin.action?popup=true");
  driver.findElement(By.id("loginId")).clear();
  driver.findElement(By.id("loginId")).sendKeys("opo.1");
  driver.findElement(By.id("loginPassword")).clear();
  driver.findElement(By.id("loginPassword")).sendKeys("opo.1");
  driver.findElement(By.id("login_")).click();
  Thread.sleep(1000);
  /*WebDriverWait wait = new WebDriverWait(driver, 10);
  WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Home")));*/

  /*Open Data Cleansing and Migration > DeDuplication & Survivorship*/
  Actions actions = new Actions(driver);
  WebElement mainMenu = driver.findElement(By.xpath("//span[contains(@class,'menu-name')]"));
  actions.moveToElement(mainMenu);  

  WebElement subMenu = driver.findElement(By.id("listpro_3"));
  actions.moveToElement(subMenu);
  actions.build().perform();
  Thread.sleep(20);

  WebElement subsubMenu = driver.findElement(By.xpath("//a[contains(text(),'DeDuplication & Survivorship')]")); 
  subsubMenu.click();

  Select dropdown = new Select(driver.findElement(By.id("ruleId")));
  dropdown.selectByVisibleText("titlecheck");
          System.out.println("The Output of the IsSelected " +
          driver.findElement(By.id("ruleId")).isSelected());
          System.out.println("The Output of the IsEnabled " +
          driver.findElement(By.id("ruleId")).isEnabled());
          System.out.println("The Output of the IsDisplayed " +
          driver.findElement(By.id("ruleId")).isDisplayed());             
             Select oSelection = new Select(driver.findElement(By.id("ruleId")));                
              oSelection.selectByVisibleText("titlecheck");               
             WebElement select = driver.findElement(By.name("ruleId"));
              Select se=new Select(select);             

se.selectByIndex(1046);

}
}



/*After method to close*/
@AfterMethod

public void closewindow()
{

    driver.quit();
}
}

1 个答案:

答案 0 :(得分:1)

页面中的表单存在于iframe

doctrine:
    dbal:
        schema_filter: ~^(?!(new_bot_b|new_com|new_str|new_geb|new_geba|new_hea|new_plz1|new_plz2|new_stra))~

您需要切换到iframe,然后访问网络元素

<iframe name="DeDuplication &amp; Survivorship_iFrame" src="SMDLT.action" class="tabIFrameStyle" scrolling="no" frameborder="0" marginwidth="0" marginheight="0" width="100%" height="500px"></iframe>

注意:如果不退出iframe,您将无法访问iframe中显示的其他内容

我已经测试了上面的代码,它运行良好

希望这会对你有所帮助。如果你有任何疑问,请回复