简体   繁体   中英

Python with selenium 2 and firebug extension

I'm not even sure if that is the solution to my problem but here we go.

So I'm trying to find a link on a webpage. The thing is the webpage seems to be executing a javascript in order to obtain the actual html code. Now here is the thing which I'm not sure under which category it would really fall.

I understand that the source code of the browser usually shows you everything after unwrapping the javascript but for this website the source code doesn't show any of the site content. Now the only way to see what is on the site content is by using firebug.

I thought by using firebug with selenium as following then I will be able to work with the xpath or something but either I don't get the point behind using firebug with selenium or I'm using it all wrong.

Can someone help please? I have been spinning hard with this one. BTW it is ASPX link if that makes a difference

from selenium.webdriver.common.keys import Keys
fp = webdriver.FirefoxProfile()
fp.add_extension(extension='firebug-1.11.2-fx.xpi')
fp.set_preference("extensions.firebug.currentVersion", "1.11.2")
browser = webdriver.Firefox(firefox_profile=fp)
browser.get("Example.com/start.aspx")
try: 
    #elem = browser.find_element_by_xpath("/html/body/div[2]/div[2]/table/tbody/tr/td[3]/a")
    elem = browser.find_element_by_link_text("SEARCH")
    elem.send_keys(Keys.RETURN)

except NoSuchElementException:
    assert 0, "can't find XPATH or Link Name"

Thanks

Actually I found my problem.

The issue for not showing the whole html code was due to not focusing on the right iframe

all I had to do is to through the following to switch to the right "iframe"

browser.switch_to_frame("iframe")

You also don't need to use firebug extension for this.

Hopefully this would help some of you who ran into similar issue.

Full code would be like this:

from selenium.webdriver.common.keys import Keys
browser = webdriver.Firefox()
browser.get("Example.com/start.aspx")
try: 
    #elem = browser.find_element_by_xpath("/html/body/div[2]/div[2]/table/tbody/tr/td[3]/a")

    browser.switch_to_frame("iframe")
    elem = browser.find_element_by_link_text("SEARCH")
    elem.send_keys(Keys.RETURN)

except NoSuchElementException:
    assert 0, "can't find XPATH or Link Name"

Regards,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM