0

I am currently using Selenium on Python to automate some stuff, and what I'd like to do is modify a specific part of an element on the source code when inspecting it.

Specifically, I want to replace Blur(12px) in the following code to Blur(0px), to remove the blurriness of the pictures:

<div class="Bdrs(8px) Bgz(cv) Bgp(c) Ov(h) StretchedBox Ir(p) Cnt($blank)::a StretchedBox::a Bg($inherit)::a Scale(1.3)::a Scale(1.2)::a--s Blur(12px)::a" style="background-image: url(&quot;https://preview.(...).com/); background-position: 50% 100%; background-size: auto 100.952%;"></div>

I am not too sure of how this can be done, and although I have done my research I was not able to find a proper solution to the problem.

1 Answer 1

2

You can use javascript to make the attribute change.

element = driver.find_element_by_css_selector("... some css selector ...") # this can be however you want to find the element
driver.execute_script("arguments[0].setAttribute('class', 'Blur(0px)')", element)

This is assuming you are using the variable 'driver' for your webdriver object.

The html sample you gave had a lot of other classes in your class attribute. If you want to retain the rest, you can get the attribute contents first, replace the Blur(12px) with Blur(0px) and then use this for your value in the javascript line.

element = driver.find_element_by_css_selector("... some css selector ...") # this can be however you want to find the element
class_value = element.get_attribute("class")
revised_classes = class_value.replace("Blur(12px)", "Blur(0px)")
driver.execute_script("arguments[0].setAttribute('class', arguments[1])", element, revised_classes)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.