NoSuchElementException - Unable to locate element

前端 未结 1 1927
粉色の甜心
粉色の甜心 2020-12-10 08:46

I have an input box like the one I am using here to enter my question, and whose HTML is



        
相关标签:
1条回答
  • 2020-12-10 08:59

    If you are getting NoSuchElementException as your provided exception, There may be following reasons :-

    • May be when you are going to find element, it would not be present on the DOM, So you should implement WebDriverWait to wait until element visible as below :-

      WebDriverWait wait = new WebDriverWait(driver, 10);
      WebElement Category_Body = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("tinymce")));
       Category_Body.sendKeys("Android Smart Phone - 16GB");
      
    • May be this element is inside any frame or iframe. If it is, you need to switch that frame or iframe before finding the element as below :-

      WebDriverWait wait = new WebDriverWait(driver, 10);
      
      //Find frame or iframe and switch
      wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("your frame id or name"));
      
      //Now find the element 
      WebElement Category_Body = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("tinymce")));
       Category_Body.sendKeys("Android Smart Phone - 16GB");
      
      //Once all your stuff done with this frame need to switch back to default
      driver.switchTo().defaultContent();
      
    0 讨论(0)
提交回复
热议问题