0

I clicked on a link which opens a small window/popup/iframe and the popup window has Xpath:

//html/body/div[2]

ie. it has no window_id but in firebug the identifier shows the window as a <div class="some_name"> so I'm assuming it's a popup window; correct me if I'm wrong.

When I use the selectPopup of selenium IDE it works fine in switching from the main window to the popup/new_window but when exporting to webdriver-python it doesn't have that option. So I tried using driver.switch_to_window and switch_to_frame along with the xpath mentioned above but no luck ie. driver.switch_to_frame(driver.find_element_by_xpath("//html/body/div[2]"))

Error thrown : NoSuchElementException and that's because it's not able to select the iframe.

Since it's working fine in Selenium IDE I exported it to python-webdriver which converted the wait_for_element clause to

for i in range(60): try: if self.is_element_present(By.XPATH, "//*[@id='heading']/div[2]/div/div/ul/li[2]/a"): break except: pass time.sleep(1) else: self.fail("time out") which returns the above error

Detailed html: //*[@id='heading']/div[2]/div/div/ul/li[2]/a is the xpath of the element and as html this is what it is <a href="/my_url/test/Home/">Home</a> and in detail: `

<div class="help">
<div class="page-header">
<div id="heading">
<div id="search">
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<ul class="nav">
<li class="active">
<li>
<a href="/my_url/test/Home/">Home</a>
</li>
<li>
<li>
<li>
</ul>
<form class="navbar-form pull-right">
</div>
</div>
</div>
</div>`
7
  • If the window that gets shown is in the same document as the page itself, then it's not a true popup. You may be able to just use driver.find_element_by_xpath
    – voithos
    Commented Jul 24, 2013 at 15:46
  • @voithos: I believe it's an iframe so I tried switch_to_frame as well in addition to driver.find_element_by_xpath; both didn't work
    – L P
    Commented Jul 24, 2013 at 15:49
  • If it's an iframe, then you seen to find_element_by_xpath the iframe itself, and then you can use driver.switch_to_frame(iframe_obj)
    – voithos
    Commented Jul 24, 2013 at 15:52
  • That's exactly what I had done and above is the xpath of the iframe/popup; so the code I tried was: driver.switch_to_frame(driver.find_element_by_xpath("//html/body/div[2]")) which didn't work
    – L P
    Commented Jul 24, 2013 at 15:54
  • Does it throw an exception of any kind?
    – voithos
    Commented Jul 24, 2013 at 16:09

1 Answer 1

-1

try out this :

new Actions(driver).click(driver.findElement(By.xpath("//div[@id='pop-up-window']"))).perform();
1
  • Please use 4 spaces in front of the code to format it as code. Commented Jan 16, 2016 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.