Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set style display of an html element in a selenium test?

Tags:

I get an element like

cv_upload = driver.find_element_by_id('id_cv_upload')

So I want to set its display as inline in python itself.is it possible with python to set the display. I tried

cv_upload.style.display = "inline"

which is showing me error.
One way which is getting into my mind is to use Jquery to change the display and then execute it using driver.execute but unfortunately I am not getting the right syntax to do this. Let me know how to do this (The syntax.) Thanks.

like image 606
NIlesh Sharma Avatar asked Aug 30 '12 13:08

NIlesh Sharma


People also ask

How do you check the color of an element in selenium?

We can verify the color of a webelement in Selenium webdriver using the getCssValue method and then pass color as a parameter to it. This returnsthe color in rgba() format.

What is xOffset and yOffset in selenium?

Both xOffset and yOffset represent the relative pixel distance (integer) with which to scroll. For xOffset , positive value means to scroll right, and negative value means to scroll left. For yOffset , positive value means to scroll downward, and negative value means to scroll upward.

How do I find HTML elements in selenium?

There are 2 ways to get the HTML source of a web element using Selenium: Method #1 – Read the innerHTML attribute to get the source of the content of the element. innerHTML is a property of a DOM element whose value is the HTML that exists in between the opening tag and ending tag.

Can selenium read HTML?

Selenium is a Python module for browser automation. You can use it to grab HTML code, what webpages are made of: HyperText Markup Language (HTML).


2 Answers

since you marked jQuery - You can use the css() function to set/get css attributes

$('#id_cv_upload').css('display','inline');
like image 89
wirey00 Avatar answered Sep 23 '22 05:09

wirey00


Finally find out the way to set display of an element.

driver.execute_script("document.getElementById('id_cv_upload').style.display='block';")

basically using driver.execute_script I am executing a java script for setting the style of an element.

like image 23
NIlesh Sharma Avatar answered Sep 21 '22 05:09

NIlesh Sharma