Utilizing Selenium WebDriver in Python to locate and interact with WebElements

Currently, I am utilizing Selenium for real-time web scraping. However, I am encountering issues searching for a specific WebElement even though the documentation indicates that it is feasible.

while True:
    try:
        member = self.pdriver.find_all("sv:member_profile")[index]
        self.pdriver.info_log("Found a member")
    except IndexError:
        self.pdriver.info_log("No more members")
        break

    member.highlight(style = self.pdriver.get_config_value("highlight:style_on_assertion_success"))

    profile = {}
    profile["name"] = member.findElement("sv:member_name").get_attribute('innerHTML')
    profile["image"] = member.findElement("sv:member_image").get_attribute('src')
    profile["link"] = member.findElement("sv:member_link").get_attribute('href')

    members.append(profile)
    index += 1

This snippet ultimately yields a singular web element:

member = self.pdriver.find_all("sv:member_profile")[index]

As outlined in the documentation, this element should also possess the findElement method. Surprisingly, this does not appear to be the case?

AttributeError: 'WebElement' object has no attribute 'findElement'

Answer №1

According to the error message, the WebElement object does not have the attribute findElement. To resolve this issue and based on the properties of sv:member_name, sv:member_image, and sv:member_link, you must decide which of the available find_element_by_* methods is appropriate for your scenario.

For example, if sv:member_name is a CSS selector:

profile["name"] = member.find_element_by_css_selector("sv:member_name").get_attribute('innerHTML')

Alternatively, you can utilize the find_element() method directly by specifying the By value:

from selenium.webdriver.common.by import By

profile["name"] = member.find_element(By.CSS_SELECTOR, "sv:member_name").get_attribute('innerHTML')

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Quick and effective way to reverse a queryset

Exploring the most effective way to navigate through my models to retrieve the desired data. I am dealing with three interconnected models: Item, ProtectionList, and Player. Protection List class ProtectionList(models.Model): player = models. ...

Navigating through xpath in Python Selenium?

a = driver.find_elements_by_xpath("//article[3]/div[3]/div[2]/a[*[local-name()='time']]") for links in a: print (links.text) This code snippet is part of a project I am developing for Instagram using Selenium. It aims to track the mo ...

Preferring an installation of a module using pip rather than relying on the default library version

Upon running ipython and other Python 2.7 programs, I encountered a warning stating "Module was already imported". This warning originates from the presence of both the standard library's argparse module and a PyPI module with the same name. In my sp ...

Is there a method to enhance the efficiency of the itertrows function in pandas?

This data represents input information To determine the Closing stock value, we consider only cases where there is a value for Opening Stock. It involves adding Opening Stock, Purchase Qty, and Sold Qty. https://i.stack.imgur.com/gpjj5.png I need to upd ...

Is there a way to programmatically click on a button or div tag repeatedly until it fades away from the webpage using Selenium in

Can someone help me retrieve all the reviews from this specific page? I have attempted to extract the reviews by repeatedly clicking on the "load more" button using xpaths provided in my code sample. However, my solution is failing and I am encountering th ...

Error encountered when passing NoneType to .send_keys in Python Selenium while using the Chrome

I'm having trouble inputting my username in the designated field on a website. Although I can open the site and click on the box, no text appears when I try to type. Additionally, a warning popup from Chrome's developer extensions keeps showing u ...

Exploring the Power of Strings in Python

I have encountered a challenge - I need to develop a program that prompts the user for their first name, saves it, then asks for their last name and does the same. The final task is to display the first name and last name in two separate rows as shown belo ...

Unusual actions observed when adding a dictionary to a list

I have created a script that reads JSON data and constructs a list of dictionaries. The JSON data structure is as follows: { "JMF": { "table1": { "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail=" ...

GeckoDriver Firefox and Protractor(Selenium) encountered a NoSuchWindowError due to the browsing context being discarded

I need assistance with running a basic test script using protractor. Environment: Node Version: v9.8.0 Protractor Version: 5.4.1 Angular Version: 1.x Browser(s): Mozilla Firefox 60.1.0 Operating System and Version: HELiOS release 6.10 Below is my config ...

The prompts.py file was given an invalid JSON data structure (Promptfoo)

When using the promptfoo tool, I faced an issue with the data passed to the prompt_generator.py script. The expected format was proper JSON, but the actual data had formatting errors. Steps to Reproduce: 1. Setting up prompt_generator file: %%writefile p ...

Troubleshooting a problem with search autocomplete using Python's Selenium

Seeking assistance with filling out an autocomplete form for zip codes and towns. Even when entering the entire information at once, validation of the autocomplete search is still required. Due to space constraints, I will not include all error messages fo ...

An issue has been identified with Selenium's FirefoxDriver and Geckodriver where the WebElement.click() method becomes unresponsive if the window is closing during

Meta Data: Selenium Version: 3.3.1 Browser: Firefox v52.0.1 (32-bit) Geckodriver Version: 0.15.0 (32-bit) Operating System: Windows 10 Java Version: 1.8_121 (32-bit) I have created two HTML files to replicate this problem. Main Window - mainWindow.htm ...

Steps to verify the element's placement on the list (Ensure it is indeed the top element on the list)

Still learning the ropes here. I am attempting to confirm that elements are arranged in descending order with the latest date being first (2019, 2018, 2017, 2016, etc). Below are the elements along with their corresponding dates: --> 2017/2018 --> 2016/ ...

Tips for renaming scraped image files using Python

I'm currently working on a project that involves downloading images of coins listed on CoinGecko. Here's the code I've come up with: import requests from bs4 import BeautifulSoup from os.path import basename def getdata(url): r = requ ...

Having problems initiating a remote session with WebDriver - encountering a TypeError: string indices should be integers

As one of my initial attempts at writing a Python script, I am working on running a test case on localhost hosted on an IIS server in a local environment. To achieve this, I have made the following adjustments: Changed Firefox Settings to 'No proxy& ...

Exploring the Power of Pandas: Enhancing DataFrames with Series Operations

My data frame includes a date column with the following format: (Year-Month-Day) 2017-09-21 2018-11-25 I've been attempting to create a function that focuses only on the year portion of the dates, like this: df[df['DateColumn'].str[:3]==& ...

Discovering the browser handle for a newly opened IE window in Selenium Java

Currently, I am focused on automation testing using Selenium with Java. In my current scenario, the first step involves opening the login page and then providing credentials before clicking the Login button. After this action is completed, the current brow ...

Creating a dynamic MPTT structure with expand/collapse functionality in a Django template

I am looking for a way to display my MPTT model as a tree with dropdown capability (open/close nodes with children) and buttons that can expand/collapse all nodes in the tree with just one click. I have searched for examples, but the best I could find is ...

Python script to scrape a webpage after giving consent for cookies

Is anyone able to assist me with a web scraping issue I am encountering? I am attempting to scrape a webpage, but I am facing an obstacle in the form of a cookie acceptance banner that appears before I can access the desired content. I have tried using sel ...

Simplifying the spectrum

list1 = [6,1,3] for item in list1: result = "" for y in range(item): result += "*" print(result) Above script will display the following output: ****** * *** I am new to Python and wondering if there is a simpler way to ac ...