Reputation: 896
I'm using selenium with python, using a Chrome webdriver to read a static html file on my disk. Some elements behave well when .size['width']
is called upon them, returning the widths with no problem. But multiple of elements, whose css width property is "auto", returns zero when I call e.size['width']
for such an element e
. Why? And how can I get the actual width of the elements? They are definitely not zero (as can be seen from the Chrome developer tools' popover tooltips) and e.value_of_css_property("width")
returns "auto", which isn't informative.
Upvotes: 0
Views: 1669
Reputation: 896
I found out somehow this is to do with my specifying the option of headless for selenium:
options = webdriver.ChromeOptions()
options.add_argument('headless')
driver = webdriver.Chrome(options=options)
remove the options.add_argument('headless')
line, and the sizes, including widths, spring back to life. Anyone knows why this is the case, and is there a way to both remain headless and get non-zero widths from .size['width']
for elements that do have non-zero width?
Upvotes: 1
Reputation: 658
did you use something like:
driver.set_window_size(1366, 768)
for defining window size? and what is e please post your code so we can help you better
Upvotes: 0