I have a program with python & selenium. I will print the program like this :

end-bubble bubble ok

end-bubble bubble high

My goals are like this:



My idea is to print without the end-bubble bubble only ok or high but I don't know how the script with python selenium.

Please give me solution.

This is my script :

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome (executable_path=r"C:\Users\rizki.abdillah\Desktop\Selenium\chromedriver.exe")
# maximize with maximize_window()
# identify element
service_status = driver.find_elements_by_css_selector("tr>.day.col8>span").get_attribute("class")
  • A more robust test would likely split the string and then verify that the class you're expecting is in the array of strings (i.e. the order of classes in CSS is not important) – ernie Apr 6 at 23:08

You can use Python's .split() function. Change the last line of your script to

print(service_status.split(' ')[2])

It will depend on what you want to tell in your code.

If you want to remove the text "end-bubble bubble", then you can use replace:

service_status.replace('end-bubble bubble','')

If you want to explicitly only take the last word of the string, you can use deconstruction:

_, _, last = service_status.split()

Or if you want to be more cryptic (don't be please):


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.