2

I am using Selenium Web Driver for Fire Fox to automate a web page inPython.

The issue is that sometime for some elements i am getting NoSuchElementException even though the element is present with the id i am searching for.

I am using find_element_by_id(id) method.

My code is

d = webdriver.Firefox()

elm5 = d.find_element_by_id("ctl00_bodyContent_tabGroupAdmin")

elm5.click()

The HTML for that element is:

<div id="ctl00_bodyContent_tabGroupAdmin" class="tab">
                <div onclick="OpenTab(3); DisableProgressBarDisplay(); return false;">
                    Group Administrators</div>
                <div class="cap_right">
                </div>
            </div>

Has anyone faced the same issue? Please suggest some work around.

Thanks

abhi
  • 3,476
  • 5
  • 41
  • 58
  • 1
    The combination of Selenium and Firefox doesnt always play nice. You really need versions that are compatible. This could be the problem. Try Chrome if that gives the same problem? [previous answer of mine](http://stackoverflow.com/a/14541128/921154) – qrazi Apr 02 '13 at 11:40

4 Answers4

3

I would suggest that you have to wait for the element to appear.

have a look at this answer about how to wait

We had this problem, too, sometimes while using selenium. The page was too slow.

Community
  • 1
  • 1
User
  • 14,131
  • 2
  • 40
  • 59
0

I don't know anything about Python, however i am working with selenium Webdriver using java, and i guess the issue lies bcz may you are not switched to the current frame. You can check this by checking your html stuff by just going up and you will be able to find the current frame.

In java we used to do this as driver.switchTo().frame(driver.findElement(By.name("officePane")));

you can check this similar in the python Hope it will help you.

0
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

add these to the beginning of your code and

WebDriverWait(d, 20).until(EC.presence_of_element_located((By.ID, "ctl00_bodyContent_tabGroupAdmin")))

BTW, you can find and click elements in a single line as:

d.find_element_by_id("ctl00_bodyContent_tabGroupAdmin").click()

good luck and thanks for User to teach this solution for us.

Community
  • 1
  • 1
Deniz Kaplan
  • 1,549
  • 1
  • 13
  • 18
0

Hope your problem is fixed now. But i was facing the same problem since last 2 weeks. Here is the below code for your problem. It will detect the frame and locate the element specially when the element is frequently detected and some times not detected.

WebDriver d = new FirefoxDriver();  <-- Intialize your Firefox driver
WebDriverWait  frame = new WebDriverWait(driver, 50); <-- Creating wait object for frame
frame.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.tagName("iframe")));
WebDriverWait wait1 = new WebDriverWait(driver, 50); <-- Creating wait object for element 
wait1.until(ExpectedConditions.elementToBeClickable(find_element_by_id("ctl00_bodyContent_tabGroupAdmin"))).click();

Hope this will solve your problem if its unsolved.

xav
  • 5,452
  • 7
  • 48
  • 57
Rupesh Shinde
  • 1,933
  • 12
  • 22