简体   繁体   中英

Clicking href javascript in Selenium with Python

I'm trying to click on href javascript link with Selenium in Python.

The HTML looks like this: HTML Example and I want to click on javascript:goType(1).

this is what I tried to do:

advance_search = browser.find_element_by_xpath("//a[@href='javascript:goType(1)']")
advance_search.click()

but it failed with: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//a"}

Moreover, when I trying to print all "a" tags it prints an empty lists (Maybe this cause the error). Is There a chance that it isn't possible?

I searched for similars answers but they didn't helped. Plese help me :).

I think I realized something: When I did browser.find_elements_by_tag_name("body") it didn't found anything, but when I tried with "head" it did found, and then I discovered that there is a 'page source' and a 'frame source', and my code works only on the page source and not on the frame source.

It doesn't finds anything because all my code is in the frame source. How could I run selenium on the frame source?

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