2

I am unable to switch into iframe and have a control on it. Here is the DOM:

<iframe class="ze_area">
#document
<html><head><link type="text/css" rel="stylesheet" href="https://css.zohostatic.com/ze/v86/css/zeditor.min.css"><style type="text/css">.ze_body{font-family:Verdana,arial,Helvetica,sans-serif;font-size:13px;} table{font-size:100%} .MsoNormal{margin: 0px}</style><style>ol.code li { word-wrap: break-word; } ol.code li pre,span,p,div {white-space: normal !important; }</style>
</head>
<body class="ze_body">
</body></html>
<iframe>

I am trying this code to run

WebElement filebug=driver.findElement(By.id("fileabugnew"));
filebug.click();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
WebElement filebug_subject=driver.findElement(By.id("fileabug_subject"));
filebug_subject.sendKeys("web erp : test failed to search for web title");
 driver.switchTo().frame(0);
WebElement 
filebug_content=driver.findElement(By.className("//body[@class='ze_body']"));
filebug_content.sendKeys("erp content. the test is failed");
WebElement click_to_assign=driver.findElement(By.xpath("//span[text()='Not 
 Assigned']"));
click_to_assign.click();
 WebElement 
  type_to_assign=driver.findElement(By.xpath("//div[@class='select2-drop 
   searchableselect2 select2-with-searchbox select2-drop- 
   active']//input[@class='select2-input']"));
type_to_assign.sendKeys("shashank.choursia");
driver.findElement(By.id("submitbug")).click();

2 Answers2

2

You need to find the index of the iframe you are trying to switch to. driver.switchTo().frame(0); means you are switching to iframe with index '0'. For more information see How to identify and switch to the frame in selenium webdriver when frame does not have id

or

WebElement iframe = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(iframe);   
// your action here
driver.switchTo().defaultContent();
theGuy
  • 683
  • 5
  • 15
  • Please share the error you are getting. Also are there any other iframes in your html code? I have updated my answer with more information – theGuy Jul 24 '18 at 18:10
  • I can share the url. You can make the most of it.Do one thing.Go to this url https://accounts.zoho.com/signin?servicename=ZohoBugTracker and make an account here.It is free to use.Make a demo project and and then try to submit the issue(file the bug).I hope this would help you out. – Die Hard Coder Jul 25 '18 at 19:50
  • 1
    @DieHardCoder, try my second answer, that worked for me. i.e. switching to frame by tagname – theGuy Jul 26 '18 at 14:33
  • @DieHardCoder, if the solution worked it should be accepted as an answer. Thanks – theGuy Jul 27 '18 at 15:54
  • I know just trying to execute the code first. @theGuy – Die Hard Coder Jul 27 '18 at 17:30
0

Initially, you need to navigate to the parent Frame for that use:

driver.switchto().defaultContent();

Once you done you could navigate to the frame in which you webelement is based on index.

driver.switchTo().frame(i);

where 'i' is the index which starts from '0'.

Hope this was helpful and queries do lemme know.

Fury
  • 142
  • 1
  • 12