-1

Attempting to open the login page and log in, at which point the link ending in server_id=... will be available, which is a panel to edit my server listing, where I then want to click the Update button at the bottom. Am I using By properly?

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()

Full error:

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
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
00dpotter
  • 11
  • 4

1 Answers1

0

Seems there is a typo within the WebDriverWait.

According to the definition, element_to_be_clickable() should be called within a tuple as it is not a function but a class, where the initializer expects just 1 argument beyond the implicit self:

class element_to_be_clickable(object):
    """ An Expectation for checking an element is visible and enabled such that you can click it."""
    def __init__(self, locator):
        self.locator = locator

    def __call__(self, driver):
        element = visibility_of_element_located(self.locator)(driver)
        if element and element.is_enabled():
            return element
        else:
            return False

So, effectively instead of:

elif expected_conditions.text_to_be_present_in_element(
    By.CLASS_NAME, 'column-heading'):
    

You need to:

elif WebDriverWait(driver, 3).until((expected_conditions.text_to_be_present_in_element(
    By.CLASS_NAME, 'column-heading'))):

Likewise, you have to change the other instances of WebDriverWait.


Reference

You can find a detailed discussion in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352