Tool for formatting inputs for selenium css selectors for multi class names (with spaces) - selenium python
When you use selenium to select an element with multiple classes using driver.find_element_by_css_selector(), you need to replace spaces with dot notation. For example, To select The following element: <i align="center" class="far fa-copy croc-copy-icon"> you 'll need to use the following selector with dot notation formatting:
driver.find_element_by_css_selector(".far.fa-copy.croc-copy-icon”)
Having to replace spaces with full stops over and over again can get repetitive and time-consuming especially for lengthy classes. Here is a quick script I use to replace all spaces with dots, and add a dot at the beginning of the string. I found this can save quite a bit of time
import pyperclip
text = "a really long multi class element t-14 t-black--light t-normal hoverable-link-text"
temp = text.replace(" ",".")
string_for_selenium_css_selector = "." + temp
pyperclip.copy(string_for_selenium_css_selector)

SNAPPED!

SNAPPED!
Comments
Post a Comment