Divya Mani
Divya Mani

Reputation: 313

How to find webelement using style property in python selenium

I want to give Click the button based on style and class name,because in my case there is no unique class name and id.

My html code is

<a class="x-btn x-unselectable rp-important-btn rp-btn-shadow x-box-item x-toolbar-item x-btn-default-small x-noicon x-btn-noicon x-btn-default-small-noicon" 
style="height: 24px; right: auto; top: 5px; margin: 0px; left: 118px;" hidefocus="on" unselectable="on" tabindex="0">

And i have tried

 save_class=driver.find_element_by_xpath("//a[@class='x-btn x-unselectable rp-important-btn rp-btn-shadow x-box-item x-toolbar-item x-btn-default-small x-noicon x-btn-noicon x-btn-default-small-noicon' 
 and style='height: 24px; right: auto; top: 5px; margin: 0px; left: 118px;']")

I am getting following error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//a[@class='x-btn x-unselectable rp-important-btn rp-btn-shadow x-box-item x-toolbar-item x-btn-default-small x-noicon x-btn-noicon x-btn-default-small-noicon' and style='height: 24px; right: auto; top: 5px; margin: 0px; left: 118px;']"}

Upvotes: 1

Views: 340

Answers (2)

CC7052
CC7052

Reputation: 577

Hi to choose with two match attribute and click the button use:

driver.find_element_by_xpath('//a[@class="x-btn x-unselectable rp-important-btn rp-btn-shadow x-box-item x-toolbar-item x-btn-default-small x-noicon x-btn-noicon x-btn-default-small-noicon" and @style="height: 24px; right: auto; top: 5px; margin: 0px; left: 118px;"').click()

Upvotes: 0

PaxPrz
PaxPrz

Reputation: 1928

You have forgot @style in your xpath

save_class=driver.find_element_by_xpath("//a[@class='x-btn x-unselectable rp-important-btn rp-btn-shadow x-box-item x-toolbar-item x-btn-default-small x-noicon x-btn-noicon x-btn-default-small-noicon' and @style='height: 24px; right: auto; top: 5px; margin: 0px; left: 118px;']")

Try this!

Upvotes: 1

Related Questions