Skip to content

Help for beginners to find and hide an element, CSS classes #2468

Answered by mdmintz
Chunkst asked this question in Q&A
Discussion options

You must be logged in to vote

Hello! Here's a sample script that hides various elements on a web page using the SB() format that has more methods than the Driver() format: (sleep() added so that you have time to see the difference).

from seleniumbase import SB

with SB() as sb:
    sb.open("https://fr.wikipedia.org/wiki/Tour_Eiffel")
    sb.sleep(1)
    sb.hide_elements("div#siteNotice")
    sb.sleep(1)
    sb.hide_elements("nav#mw-panel-toc")
    sb.sleep(1)
    sb.hide_elements('img[src*="Tour_Eiffel_Wikimedia"]')
    sb.sleep(2)

To hide only the first matching selector found, use hide_element(selector) instead of hide_elements(selector).

For the full French experience, here's a SeleniumBase example using the French…

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@Chunkst
Comment options

@mdmintz
Comment options

@Chunkst
Comment options

@Chunkst
Comment options

@mdmintz
Comment options

Answer selected by mdmintz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants