简体   繁体   中英

Unable to locate element with python and selenium

i want to click on button that means next and it wrote by 'بعدی'
in this page
https://www.tgju.org/profile/price_dollar_rl/history
here is my code

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.add_argument("--headless")
browser= webdriver.Firefox(options=options, executable_path="geckodriver.exe")
browser.get('https://www.tgju.org/profile/price_dollar_rl/history');
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
wait = WebDriverWait(browser,20)
from selenium.webdriver.common.by import By
browser.find_element_by_xpath('//*[@id="DataTables_Table_0_next"]')

and I get this error
Unable to locate element: //*[@id="DataTables_Table_0_next"]
but i copy exact id form inspect
thanks

You need to add a wait for element to be present. On this page it looks like it's dynamically loaded.

element = WebDriverWait(browser, 10).until(
        EC.presence_of_element_located((By.ID, "DataTables_Table_0_next"))
    )

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