0

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

can someone please help? maybe show me a way to do it and then explain how to find?

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

I want selenium to do the following:

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

can someone advise?

1
  • where you want to click ?/ Commented Jun 17, 2018 at 6:24

2 Answers 2

1

@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()
Sign up to request clarification or add additional context in comments.

Comments

1

You can use below code to click on link:-

element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.CLASS_NAME, "search_list_image"))
link = driver.find_element_by_link_text("God of War (2018)")
link.click()

Comments

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.