I am struggling with a problem in Selenium using Python.
This is a dummy draft of what I have.
<body> <button info="content1" aria-label="1">"Click 1"</button> <button info="content1" aria-label="2">"Click 2"</button> <button info="content2" aria-label="2">"Click 2"</button> <button info="content2" aria-label="4">"Click 4"</button> <body>
My target is to select the button that has info="content1"
and aria-label="2"
I have already tried
element=driver.find_element_by_css_selector('button[info="content1"] and button[aria-label="2"]')
But doesn’t work and returns NoSuchElementException
Would you please help me?
Advertisement
Answer
Simply put the two bracketed attribute selectors next to each other with no and
:
element = driver.find_element_by_css_selector('button[info="content1"][aria-label="2"]')