简体   繁体   English

Python,Selenium-无法找到ID为“ next”的网页元素(按钮)

[英]Python, Selenium - can't locate a webpage element (button) with ID 'next'

I started learning python with selenium to automate some of my tasks. 我开始用硒学习python以自​​动化一些任务。 I have a problem which I'm unable to solve. 我有一个无法解决的问题。
I'm trying to create a script which would automatically click the 'next' button. 我正在尝试创建一个脚本,该脚本将自动单击“下一步”按钮。 I can't locate a webpage element (button) with ID 'next'. 我找不到ID为“下一个”的网页元素(按钮)。 I tried every possible solution - by ID, by xpath etc. 我尝试了所有可能的解决方案-通过ID,通过xpath等。
It's possible that part of the webpage in which I'm trying to find the element is dynamically generated by jquery. 我试图在其中查找元素的网页部分可能是jquery动态生成的。
This is the error I get: 这是我得到的错误:

Unable to locate element: [id="next"] 无法找到元素:[id =“ next”]

Here is what I've done until this point (fragments): 到目前为止,这是我所做的(片段):

from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
import time
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

browser = webdriver.Firefox(executable_path=r'C:\Users\technik 
informatyk\Desktop\python\geckodriver.exe')

browser.get('https://it-szkola.edu.pl/usr')
browser.maximize_window()
browser.implicitly_wait(3)

zgoda = browser.find_element_by_xpath('//*[@id="cookieLayerBoxButton"]')
zgoda.click()

browser.implicitly_wait(10) 
emailElem = browser.find_element_by_id('login-box-field-input')
emailElem.send_keys('mylogin')

passwordElem = browser.find_element_by_id('password')
passwordElem.send_keys('mypassword')
passwordElem.submit()
time.sleep(2)
aktualnosci = browser.find_element_by_id('hBLAkt').click()
grandtest = browser.find_element_by_xpath('//* [@id="New178"]/div[2]/div[1]/p[2]/a').click()
lista = browser.find_element_by_link_text('Lista testów').click()
test = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH,"/html/body/div[2]/div[1]/div[2]/table/tbody/tr[5]/td[5]/a"))).click()

#browser.refresh()
#time.sleep(2)
nastepne = browser.find_element_by_id("next")

#nastepne = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.LINK_TEXT, "Następne")))
#nastepne = browser.find_element_by_link_text('Następne').click()
nastepne.click()

Screenshots 截图 码 ,

PIC1 ,

PIC2 ,

PIC3 ,

PIC4 ,

PIC5

Your help will be much appreciated. 非常感谢您的帮助。

Try xpath: browser.find_element_by_xpath('//button[@id="next"]') 尝试使用xpath: browser.find_element_by_xpath('//button[@id="next"]')

Try getting all buttons: 尝试获取所有按钮:

btns = browser.find_elements_by_xpath('//button')
for btn in btns:
    txt = btn.text
    if txt == 'Następne':
         btn.click()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM