尝试打开登录页面并登录,此时以结尾的链接server_id=...
将可用,这是一个用于编辑我的服务器列表的面板,然后我想单击底部的更新按钮。我使用By
正确吗?
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
driver = webdriver.Chrome(executable_path='C:/bin/chromedriver.exe')
driver.get('https://minecraft-server-list.com/login/login.php')
WebDriverWait(driver, 3).until(
expected_conditions.text_to_be_present_in_element(
By.NAME, 'username') or
expected_conditions.text_to_be_present_in_element(
By.CLASS_NAME, 'column-heading'))
if expected_conditions.text_to_be_present_in_element(
By.NAME, 'username'):
user = driver.find_element_by_name('username')
pw = driver.find_element_by_name('password')
user.clear()
user.send_keys('redacted')
pw.clear()
pw.send_keys('redacted')
driver.find_element_by_name('Submit').click()
WebDriverWait(driver, 3).until(
expected_conditions.text_to_be_present_in_element(
By.CLASS_NAME, 'column-heading'))
driver.get('https://minecraft-server-list.com/login/edit_server.php?server_id=redacted')
WebDriverWait(driver, 3).until(
expected_conditions.text_to_be_present_in_element(
By.CLASS_NAME, 'serverdatadiv1'))
driver.find_element_by_name('button').click()
driver.quit()
elif expected_conditions.text_to_be_present_in_element(
By.CLASS_NAME, 'column-heading'):
driver.get('https://minecraft-server-list.com/login/edit_server.php?server_id=redacted')
WebDriverWait(driver, 3).until(
expected_conditions.text_to_be_present_in_element(
By.CLASS_NAME, 'serverdatadiv1'))
driver.find_element_by_name('button').click()
driver.quit()
driver.quit()
完整错误:
Traceback (most recent call last):
File "C:/Users/veggie/Desktop/devshit/projects/mcslUpdater/main.py", line 14, in <module>
By.CLASS_NAME, 'column-heading'))
File "C:\Users\veggie\Anaconda3\lib\site-packages\selenium\webdriver\support\wait.py", line 71, in until
value = method(self._driver)
File "C:\Users\veggie\Anaconda3\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 209, in __call__
element_text = _find_element(driver, self.locator).text
File "C:\Users\veggie\Anaconda3\lib\site-packages\selenium\webdriver\support\expected_conditions.py", line 411, in _find_element
return driver.find_element(*by)
TypeError: find_element() takes from 1 to 3 positional arguments but 5 were given