Tips for utilizing a CSS selector to find a single element with two attributes simultaneously in Selenium using Python

Currently, I am using Selenium Python Css selector to target 1 component with 2 attributes simultaneously, both of which should be partially matched.

Successfully located the element with Xpath:

fifth_item = driver.find_element_by_xpath("/html/body/div[contains(@id, 'coption') and @style='display: block;']") 

When attempting:

fifth_item = driver.find_element_by_css_selector("div[id*='coption')][style*='display: block;']")

Unfortunately, it failed.

The relevant HTML snippet is provided below:

<div id="coption5" class="copt" style="display: block;">...</div>

Anyone able to offer assistance?

Answer №1

Kindly attempt using the following CSS:

fifth_item = driver.find_element_by_css_selector("div[id^='coption''][style='display: block;']")

Note: Please ensure to properly handle both double and single quotes as I am typing from my mobile keypad.

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

Finding the initial channel points icon on twitch.tv/esl_csgo through Selenium and Python

While watching the livestream on the ESL CS:GO Twitch channel, I encountered an issue when trying to click on the channel points button/icon. Every time I attempt to do so, I receive an error message stating: "no such element: Unable to locate element." De ...

Utilizing Selenium in Python to retrieve links from a webpage's table in a specific order

Is there a way to efficiently retrieve links of pdfs from the following URL using Selenium with Python? Successfully scraped the table containing rows and corresponding pdf links. driver.get(company_link) announcement_link = driver.find_element(By.XPATH, ...

Guide to creating a new browser tab with Selenium WebDriver in Java

Is there a way to launch a new tab within the current Firefox browser using Selenium WebDriver (also known as Selenium 2) in Java? ...

Having trouble locating an element with text while scrolling on an Android emulator

I am currently using Appium desktop server version 1.15, java-client version 7.3.0, and selenium-server version 3.141.59. While working on my android emulator, I encountered a situation where I needed to scroll down to view a specific text and then stop t ...

Streamline the OAuth process for Dropbox API by automating the login with just a click of a button

Currently, I am facing an issue with logging into Dropbox using the official Dropbox API in order to upload a file. The problem lies in the code not clicking on the submit button for login authentication. Rather than producing an error, the code simply han ...

What is the process for integrating AutoIT in WebDriver within a Selenium Grid setup?

I have successfully set up Selenium Grid (Node and Hub) and am currently testing a web application. However, I need to perform certain actions on the Windows Open dialog box. Can this be achieved using AutoIt with the following code: capabilities.setCapa ...

Testing the integration between Oracle and Selenium

For integration testing, I am looking to test some connections between a web application and its Oracle DB data store. There is a specific table where I want to verify the stored values. I am contemplating the most effective method to accomplish this task ...

Is there a way for me to engage with the content on the page prior to it

Currently, I am facing an issue while using selenium with python. My intention is to interact with a page that has the following structure: driver_window_manager.get(url) iframe = driver_window_manager.find_elements_by_tag_name('iframe')[0] driv ...

What are the steps for integrating Jenkins CI with Selenium?

Currently, I have reached a point where I am capable of constructing my own test automation framework using TestNG with Selenium. My next objective is to automate runs periodically by incorporating Selenium Grid. I've been conducting some research on ...

Error Encountered: Codeception WebCurlException

Currently, I am using Codeception in conjunction with Selenium Webdriver and encountering a WebCurlException Error once I execute codecept.phar. Here are the steps I've taken: 1. I initiated the selenium stand alone server jar file via the command p ...

Having trouble launching Firefox using Selenium WebDriver

Oops, encountered an error: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 148, in __init__ self.service.start() File ...

Tips for changing window size using Selenium WebDriver and Python

Is there a way to resize the browser window (e.g. chrome window) using selenium webdriver with python? A related question can be found in reference 1, but it does not offer a satisfactory solution and only adds confusion. The answer provided here address ...

Need help automating clicking the download csv button with Selenium Python, but the button's class name changes when it's hovered over?

While attempting to save a csv file by clicking the download csv button on a website, I encountered an issue. It seems that the .click() action is not functioning as expected, and upon inspection, I noticed that the class-name of the button changes from &a ...

Exploring FreeBSD with pyvirtualdisplay and Python 2.7 for Selenium Web Driver operations

Here is the code I wrote for FreeBSD. Prior to this code, I executed pkg install xorg-vfbserver However, I am unsure of which environment variable to set after this. In Ubuntu, you must follow these steps before using this program: apt-get install xvfb ...

Iterate through and append to a list

My current goal is to create a list of URLs named visit_urls that I need to visit. To begin with, I manually provide the first URL to be visited using self.br.get(url). By determining the number of pages on the website, let's say it has 40 pages, I ca ...

Investigating the Hierarchy of CSS Selectors

I've been pondering this question: What exactly is the functional distinction between these two code snippets, if any? I'm not certain how the use of a comma impacts statements. Does the #page > have an influence on the link in the first example? ...

Using the MoveToElement and click functions in Protractor with Node.js for automated browser

Trying to click on a checkbox in our application. I have successfully implemented it in Selenium Java using the code below, but struggling to do the same in Protractor Node.js. Any assistance would be appreciated. Selenium- Java : Actions actions ...

Python Selenium failing to reach the end of the webpage scroll

I'm currently working on developing a program in Selenium that loads a webpage and automatically scrolls to the bottom of the page. While my program successfully loads the page, it is having trouble scrolling to the bottom. Below is the complete code ...

What methods are available for me to apply an assertion specifically on the type of currency

Currently, I am hardcoding currency values like USD and CAD to perform assertions on the type of currency I receive from the application response. While using an XML file to store all currency types for comparison is possible, it seems like overkill for ju ...

What is the best way to extract data from various webpages connected to a single source using selenium?

Lately, I've been working on extracting a large amount of pricing data from a website by starting with one page that contains links to each item's individual page. My goal was to automate the process using a script that would click on a specific ...