I’m using Python and selenium to scan a web page and I want to click on a button that looks like this:
Later>
which is defined as:
<div class=”later___16eg8 col-xs-3of12”>
<button class=”visible-xs-inline visible-sm-inline visible-md-inline bdp___2gfNX textButton___ETrkF” data-test=”later-small-button”> == $0
“Later”
<span aria-hidden=”true”>></span>
</button>
<button class=”visible-lg-inline visible-xl-inline bdp___2gfNX textButton___ETrkF” data-test=”later-large-button”>
“Later”
<span aria-hidden=”true”>></span>
</button>
</div>
I tried:
later = driver.find_element_by_xpath('//button[text()="Later"]')
later.click()
and while the first line finds the button (or part of it), the second generates the following error:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
I also tried:
later = driver.find_element_by_xpath('//button[text()="Later>"]')
and this generated the following error:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//button[text()="Later>"]"}
Any ideas?
Thanks
Have u tried //div[#class='later___16eg8 col-xs-3of12']/button/button[text()='Later']
Related
EDIT FROM FUTURE, MAY BE YOUR SOLUTION: The page that I was trying to deal with opens on a new tab which I've missed to notice. My driver was trying to find the element on the very first tab, that is why it was unable to locate element.
--
--
--
I tried all solutions on Stackoverflow, however still got the same problem.
I am trying to select a specific option from a dropbox. It looks like this:
click to see the dropbox.
The HTML that belongs to this dropbox is as follows:
<td ct="GLC" lsdata="{1:'STANDARD'}" id="WD18" class="lsContainerCell lsGLCTopVAlign lsContainerCellVAlign--top urLayoutDefault--grid" valign="TOP" align="left" style="white-space:normal;"><span id="WD19-r" class="lsField lsField--standalone lsField--explicitwidth lsField--hasellipsis lsField--hashelp lsField--list lsField--focus lsField--interactiontarget" aria-live="assertive" style=""><input id="WD19" ct="CB" lsdata="{2:'WD1A',3:'10',4:'2021\x2f2022',27:'WD17'}" lsevents="{Select:[{ResponseData:'delta',EnqueueCardinality:'single'},{}]}" type="text" autocomplete="off" tabindex="0" ti="0" class="lsField__input" readonly="" value="2021/2022" role="combobox" aria-haspopup="listbox" aria-readonly="false" aria-controls="WD1A" aria-expanded="false" aria-autocomplete="list" style="width:150px;" title=""><span id="WD19-btn" class="lsField__help" tabindex="-1" ti="-1" aria-hidden="true" role="button"></span></span></td>
Nothing I have tried did work because Selenium can not locate element. I've tried it with By.ID and By.XPATH. Last thing I have tried is this:
driver.find_element(By.XPATH, "/html/body/table/tbody/tr/td/div/div[1]/span/span[1]/table/tbody/tr[2]/td/table/tbody/tr[1]/td[2]")
But I still got the same error for the thousandth time:
Message: no such element: Unable to locate element
Thanks in advance.
Try this Xpath, avoid absolute path (click element, get xpath -_-)
driver.find_element(By.XPATH, "//td[#ct='GLC']")
I am trying to click on the cancel button which is in the print document in chrome. So here is the HTML
<cr-button class="cancel-button" aria-disabled="false" role="button" tabindex="0">
Cancel
</cr-button>
I have tried the following but did not work
driver.get(resume_url)
driver.maximize_window()
# Trial
driver.find_element_by_css_selector('cancel-button').click()
# Trial
driver.find_element_by_link_text('Cancel').click()
Nothing of these were successful and it returned the following error:
Message: no such element: Unable to locate element: {"method":"link text","selector":"Cancel"}
(Session info: chrome=89.0.4389.114)
Locating elements by link text only works for anchor elements.
https://selenium-python.readthedocs.io/locating-elements.html#locating-hyperlinks-by-link-text
To use the class name as a selector, you just append a period to the beginning. Does this work?
driver.find_element_by_css_selector('.cancel-button').click()
I'm testing if a website has thrown an error and I myself get an error to see if this happens.
So far I am just seeing if a button is clickable so if the button is not clickable/not displayed, then the program is okay to proceed. But if an error is there I need to return a value.
try:
dismissBtn = WebDriverWait(driver, 2).until(EC.element_to_be_clickable((By.XPATH, "//input[#value='Dismiss this error']")))
print("Reg Error Button is clickable")
finally:
print("No error")
The error is below
dismissBtn = WebDriverWait(driver, 2).until(EC.element_to_be_clickable((By.XPATH, "//input[#value='Dismiss this error']")))
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
HTML Code is below
<div id="6823e3dd-d694-4a3e-99ae-6c074e3af73d" class="unite-error-panel errorPanel unite-component">
<span class="unite-h1-no-image">An error occurred.</span>
<ul>
<li>We are unable to connect to our servers right now. Please try again later.</li>
</ul>
<div id="8977e4fa-bb61-4a51-8b56-5e051b7f95d1" class="unite-error-code" style="display: none;"> {"code":"GENERIC","httpStatus":0}</div>
<div id="0b57d2f0-a8c4-4b7e-8095-ae09054cb053" class="unite-error-close">
<input type="button" value="Dismiss this error">
</div>
</div>
Is there another way I can go around this?
The relevant text based HTML of the element would have helped us to analyze if the Locator Strategy you are using identifies the desired element uniquely. Assuming the element is uniquely identified, as it is a error message:
It can be within a Modal Dialog Box
It may need some delta time to appear within the DOM Tree.
Perhaps increasing the waiting time from 2 seconds to 5 seconds will solve the issue.
Im trying to locate and click an element (checkbox) from a big selection of checkboxes on a html site using python and selenium webdriver. HTML code looks like this:
HTML Code
<div class="checkbox-inline col-md-5 col-lg-3 col-sm-6 m-l-sm rightCheckBox">
<input type="checkbox" checked="checked" class="i-checks" name="PanelsContainer:tabsContentView:5:listTabs:rights-group-container:right-type-view:2:right-view:2:affected-right" disabled="disabled" id="id199"> <label>Delete group</label>
</div>
My problem is that the only unique identifier is:
<label>Delete group</label>
All other elements/id's/names are used by other checkboxes or changes from page to page.
I have tried the following code:
driver.find_element_by_xpath("//label[contains(text(), 'Delete group')]").click()
But I only get error when using this.
Error: element not interactable
Anyone able to help with this?
Try the below xpath
//label[contains(text(), 'Delete group')]//ancestor::div//input
Try with Javascript.
checkBox = driver.find_element_by_xpath("//label[text()='Delete group']//ancestor::div//input")
# Scroll to checkbox if its not in screen
driver.execute_script("arguments[0].scrollIntoView();", checkBox)
driver.execute_script("arguments[0].click();", checkBox)
Note : As per HTML shared by you, checkbox is in Disabled state, so i am not sure click will trigger any action. However above code will click your checkbox.
I am trying to use the Python Selenium API in order to click on a button. The HTML code is as follows:
<button class="btn wizard-next btn-primary" type="button">Weiter</button>
How to best identify this element? I was trying the following code
driver.find_element_by_class_name("btn wizard-next btn-primary").click()
but got an error
selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Compound class names not permitted
What else can I do to select this element?
You cannot use find_element_by_class_name() if class name value contains spaces.
Try:
driver.find_element_by_xpath("//button[#class='btn wizard-next btn-primary']").click()
You can use css selector also
driver.find_element_by_css_selector("btn").click()