Python-Selenium,Unable to find element with xpath in IE browser

847 views
Skip to first unread message

zhaogu...@163.com

unread,
Oct 14, 2011, 3:03:11 AM10/14/11
to Selenium Users
Can someone tell me what I'm doing wrong?
1. The codes as below could be run in Firefox normally ,but if they
are run in IE browser and I get an error:
selenium.common.exceptions.NoSuchElementException: Message: u'Unable
to find element with xpath == /html/body/form/table/tbody/tr/td[2]/
input'

from selenium import webdriver
import time
from selenium.webdriver.common.by import By

#driver=webdriver.Firefox()
driver=webdriver.Ie()

driver.get("http://db5v3.y1f1r1.test:8080/centrifydc-samples/")
time.sleep(3)
driver.find_element_by_xpath("/html/body/ul/li/a").click()
time.sleep(3)
driver.find_element_by_xpath("/html/body/form/table/tbody/tr/td[2]/
input").send_keys("Andy")

2. How to use implicitly_wait() method? Could I use it for wait page
loading ?

Eg:
driver.get("http://db5v3.y1f1r1.test:8080/centrifydc-samples/")
driver.implicitly_wait(30)

It's right ?

SiKing

unread,
Oct 14, 2011, 10:38:02 AM10/14/11
to Selenium Users
IE does not normally insert the tbody element. Try to optimize your
XPath before actually using it. Something like //table//tr/td[2]
should work for all browsers.


On Oct 14, 12:03 am, "zhaoguoca...@163.com" <zhaoguoca...@163.com>
wrote:

bruce

unread,
Oct 14, 2011, 3:11:54 PM10/14/11
to seleniu...@googlegroups.com
as a followup...

when using the xpather app with firefox.. it often (as in almost
everytime) inserts a "tbody" element in the DOM.. never been able to
determine why???

however, the bottom line is that you need to be sure the elements in
the returned XPath from firefox are really in the html/DOM..

most of the time, you can simply remove the tbody, but check to be sure.

> --
> You received this message because you are subscribed to the Google Groups "Selenium Users" group.
> To post to this group, send email to seleniu...@googlegroups.com.
> To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.
>
>

Mark Collin

unread,
Oct 17, 2011, 4:19:27 AM10/17/11
to seleniu...@googlegroups.com
Because there should be a tbody element in there but most people don't
bother adding them. I personally notmally do:

//table/descendant::tr/td[2]

To make sure the occasional tbody doesn't trip me up.

as a followup...


--
This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

If you have received this email in error please notify postm...@ardescosolutions.com

zhaogu...@163.com

unread,
Oct 17, 2011, 8:52:33 PM10/17/11
to Selenium Users
Thank you guys, I enhanced my Xpath expression and fixed this
problem. :).

By the way , anybody could answer the second question in #item1?
> > It's right ?- Hide quoted text -
>
> - Show quoted text -

Paras Jain

unread,
Nov 21, 2013, 7:59:18 AM11/21/13
to seleniu...@googlegroups.com

Hi,

Also,I am using IE10, but Unable to find element using Python.

I am using "IE driver" with Selenium Python bindings,
I got the following exception:
         NoSuchElementException: Message: u'Unable to find element with id/Xpath/CSS


Note:- Same Element is working with Firefox, IE9 and Chrome.

Code is :

      global driver driver=webdriver.Ie()

   driver.get("http://www.google.co.in/")

   driver.find_element_by_id("gbqfba")



Thanks In Advanced...
Reply all
Reply to author
Forward
0 new messages