Home > Backend Development > Python Tutorial > Can Selenium's EC.presence_of_element_located Use Class Selectors Instead of IDs?

Can Selenium's EC.presence_of_element_located Use Class Selectors Instead of IDs?

Patricia Arquette
Release: 2024-12-07 15:04:23
Original
960 people have browsed it

Can Selenium's EC.presence_of_element_located Use Class Selectors Instead of IDs?

Can you use Selenium's EC.presence_of_element_located with a class selector instead of an ID selector?

You're trying to use Selenium's EC.presence_of_element_located method to wait for an element with the class ng-binding ng-scope to become present on a web page, but it's not working. The error message you're getting is:

Message: invalid selector: Compound class names not permitted
Copy after login

This error occurs because EC.presence_of_element_located does not support using multiple class names in its selector.

Solution

To wait for an element with a specific class using Selenium, you can use the By.CLASS_NAME locator. Here's how you can modify your code:

element = WebDriverWait(driver, 100).until(EC.presence_of_element_located((By.CLASS_NAME, "ng-binding ng-scope")))
Copy after login

This code will wait for an element with the class ng-binding ng-scope to become visible on the page.

Additional Notes

In some cases, you may also need to use the EC.visibility_of_element_located method instead of EC.presence_of_element_located. This method will wait for the element to become not only present but also visible on the page.

The above is the detailed content of Can Selenium's EC.presence_of_element_located Use Class Selectors Instead of IDs?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template