seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
4.67k stars 929 forks source link

find_element function does not work on selenium web element #2916

Closed luey-punch closed 1 month ago

luey-punch commented 1 month ago
def find_buttons_with_review_ids(self, uniq_id):
    """
    Finds all buttons with both data-review-id and data-href attributes.
    """
    base_path = (
        f"{BASE_XPATH}div/div[1]/div/div/div[2]//button"
    )
    elements = self.find_elements(base_path)
    print(f"rev_elements {elements}")
    reviewers = []
    for element in elements:
        review_id = element.get_attribute("data-review-id")
        print(f"\nreview_id  {review_id}")
        if review_id:
            review_divs = element.find_element("//div")
            print(f"\nreview_divs  {review_divs}")
            review_spans = element.find_element("//span")
            print(f"\nreview_spans  {review_spans}")

    return reviewers

I get an error saying invalid argument: invalid locator Adding the 'by' param returns WebElement.find_elements() got multiple values for argument 'by'

Even using element.find_elements("//span","xpath") still throws an error

mdmintz commented 1 month ago

Duplicate of https://github.com/seleniumbase/SeleniumBase/discussions/2895#discussioncomment-9930193

WebElements use the original Selenium API, where the by arg comes before the selector. Your call would be: element.find_elements("xpath", "//span")