用硒找不到我在Javascript中需要的元素以单击链接 [英] can't find the element I need in Javascript with selenium to click on link

查看:83
本文介绍了用硒找不到我在Javascript中需要的元素以单击链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到需要告诉硒元素的元素,我想让它单击它,我相信这是因为该页面是由javascript生成的

I can't find the element I need to tell selenium that I want it to click it, I believe it is because the page is generated by javascript

可以有人请帮忙吗?

我正在工作的网站是www.howlongtobeat.com

the website I'm working on is www.howlongtobeat.com

我要硒执行以下操作:

转到 http://www.howlongtobeat.com =>单击搜索选项卡=>输入战争之神(2018) =>单击弹出的链接

go to http://www.howlongtobeat.com => click on the search tab => enter "God of War (2018)" => click the link that pops up

这是我到目前为止的代码:

this is the code I have so far:

from selenium import webdriver  
from selenium.common.exceptions import NoSuchElementException  
from selenium.webdriver.common.keys import Keys 
from requests import get
from bs4 import BeautifulSoup

url = "http://www.howlongtobeat.com"
driver = webdriver.Chrome()
driver.get(url)

search_element = driver.find_element_by_name("global_search_box")
search_element.clear()
search_element.send_keys("God of War (2018)")
search_element.send_keys(Keys.RETURN)


#this is where my isssue is, I dont know what element it is or how to find
link = driver.find_element_by_link_text("input")
link.click()

这只是我需要帮助的最后一步

it's just the last step I need help with

有人可以建议吗?

推荐答案

@Ankur Singh解决方案效果很好。您还可以使用CSS选择器进行相同的单击(我通常更喜欢CSS选择器)

@Ankur Singh solution works fine. You can also use the CSS Selector to do the same clicking (I generally prefer CSS Selectors)

element=WebDriverWait(driver,10).until(EC.presence_of_element_located((By.CSS_SELECTOR,"h3.shadow_text")))
element1= driver.find_element_by_css_selector('h3.shadow_text > a')
element1.click()
time.sleep(3)
driver.quit()

这篇关于用硒找不到我在Javascript中需要的元素以单击链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆