Alan
Alan

Reputation: 3

I can't found Element because of frame

I'm trying to design an auto-booking system. So I need to found a element: driver.find_element_by_link_text("予約可").

I can find the element if the element is visible after loading. (in the code example it means the element is located 02:00-05:30 this range) So I try to find the frame, but I failed. I've been trying to found the solution for two days.

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException 


driver = webdriver.Chrome()

url = 'https://eikaiwa.dmm.com/list/?data%5Btab1%5D%5Bstart_time%5D=02%3A00&data%5Btab1%5D%5Bend_time%5D=25%3A30&data%5Btab1%5D%5Bgender%5D=0&data%5Btab1%5D%5Bage%5D=%E5%B9%B4%E9%BD%A2&data%5Btab1%5D%5Bfree_word%5D=Kim+Khim&date=2019-06-13&tab=0&sort=6'

driver.get(url)   


try:
    button = driver.find_element_by_link_text("予約可")
    driver.execute_script("arguments[0].scrollIntoView(false);", button) # move to the position of the button    
except NoSuchElementException:
    print('not found any opening')

Upvotes: 0

Views: 48

Answers (1)

john
john

Reputation: 56

The element you want is not scrolled so can not interact.

You can find the element in the following way:

button.location_once_scrolled_into_view

But I could not find the link text, I found the class name instead.

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException 

driver = webdriver.Chrome()

url = 'https://eikaiwa.dmm.com/list/?data%5Btab1%5D%5Bstart_time%5D=02%3A00&data%5Btab1%5D%5Bend_time%5D=25%3A30&data%5Btab1%5D%5Bgender%5D=0&data%5Btab1%5D%5Bage%5D=%E5%B9%B4%E9%BD%A2&data%5Btab1%5D%5Bfree_word%5D=Kim+Khim&date=2019-06-13&tab=0&sort=6'

driver.get(url)   

try:
    #button = driver.find_element_by_link_text("予約可")
    button = driver.find_element_by_class_name("bt-open")
    button.location_once_scrolled_into_view
    button.click()
except NoSuchElementException:
    print('not found any opening')

Upvotes: 1

Related Questions