简体   繁体   English

如何使用 selenium webdriver 处理动态更改 iframe id

[英]how to handle dynamically changing iframe id using selenium webdriver

iframe id=pngNewCase1143241142570_IFrame ., this id changes dynamically every time how can i handle this in selenium webdriver java I tried using iframe id=pngNewCase1143241142570_IFrame .,每次我如何在selenium webdriver Z93F725A07423FE1C889F448B3中尝试处理这个 id 都会动态变化

driver.switchTo().frame(driver.findElement(By.xpath("Xpath of Iframe which changes dynamically")));
driver.switchTo().defaultContent();

but didn't work for me但对我不起作用

also tried也试过

driver.switchTo().frame(driver.findElement(By.Id("pngNewCase1143241142570_IFrame")));
driver.switchTo().defaultContent();

can anyone help me please谁能帮帮我

If your iframe has a src attribute try to mention it in ur xpath declaration. 如果您的iframe具有src属性,请尝试在ur xpath声明中提及它。 Its working for me. 它为我工作。 Try like below 尝试如下

WebElement frame=driver.findElement(By.xpath("//iframe[@src='showNewClaimForm.action']");
driver.switchTo().frame(frame);

您应该考虑使用带有ID的Xpath包含“// iframe [contains(@ id,'frame')]”

    int size = driver.findElements(By.tagName("iframe")).size();
    System.out.print("Total Frames --"+size);

    
    for(int i=0; i<=size; i++){
        driver.switchTo().frame(i);
        int total=driver.findElements(By.xpath("//*/th[1]/div/span/a[@id='pui_colmenu']")).size();
        System.out.println(total);
        driver.switchTo().defaultContent();}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM