I just want to click on the next page button for user reviews but every way that I have tried to find the element I just get a NoSuchElementException. Below is the button element and a little bit of my code. Thanks.
<button class="js-prev-next-paging-next btn prev-next-paging__button prev-next-paging__button-right" data-direction="next" data-qa="next-btn">
<span class="prev-next-paging__button-text">Next</span>
</button>
driver.get('https://www.rottentomatoes.com/m/forrest_gump/reviews?type=user')
driver.find_element(By.CLASS_NAME,'js-prev-next-paging-next btn prev-next-paging__button prev-next-paging__button-right').click()
Related
I am using selenium version 4.0.0, for reference.
I'm trying to click a Vuetify card element, which is acting as a button, but I running into an element not interactable: [object HTMLDivElement] has no size and location or just element not interactable errors. I have been able to solve similar problems with action chains in the past, but it doesn't seem to work with this.
This is the list element the button is contained within:
<li class="lu-li list-item" data-v-711d8d7a="" style="display: flex;">
<div class="addCard v-card v-card--link v-sheet theme--light" data-v-711d8d7a="" tabindex="0" onselectstart="return false;">
::before
<i class="v-icon notranslate btnAdd material-icons theme--light enableIcon" data-v-711d8d7a="" aria-hidden="true">
add
::after
</i>
</div>
</li>
The first things I tried was simply clicking on the element, and then clicking on the <i> element beneath it when that didn't work:
addQLButton = driver.find_element(By.CLASS_NAME, "addCard")
addQLButton.click()
addQLButton = driver.find_element(By.CLASS_NAME, "btnAdd")
addQLButton.click()
I have already tried using WebDriverWait on both the v-card <div> and <i> element to make sure they are available before being clicked, which it passes without any issues:
WebDriverWait(driver, timeout=10).until(lambda d: d.find_element(By.CLASS_NAME, "addCard"))
WebDriverWait(driver, timeout=10).until(lambda d: d.find_element(By.CLASS_NAME, "btnAdd"))
I have already tried using action chains to make sure the elements are visible (this has worked in the past with similar errors), but I still run into the same issue:
addQLButton = driver.find_element(By.CLASS_NAME, "addCard")
actions.move_to_element(addQLButton).perform()
driver.execute_script("arguments[0].click();", addQLButton)
addQLButton = driver.find_element(By.CLASS_NAME, "btnAdd")
actions.move_to_element(addQLButton).perform()
driver.execute_script("arguments[0].click();", addQLButton)
The elements are not in an iframe, and I am sure I have the correct window selected as I am still able to interact with its elements.
I am at a bit of a loss, any help would be much appreciated. I'm happy to answer any clarifying questions if I didn't explain the issue clearly enough.
I managed to get it working with some javascript:
js = "document.querySelector('.btnAdd').click();"
driver.execute_script(js)
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'm trying to find the following button and click it:
<div id="subText" class="btn btn-success">Subscribe</div>
I already tried to find the button with the following:
driver.find_element_by_css_selector('div.btn.btn-success').click()
but I get the following error:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <div id="subText" class="btn btn-success">...</div> is not clickable at point (408, 513). Other element would receive the click: <div class="delete-overlay white" style="">...</div>
Is there a way to search only for the button with the "Subscribe" text and click it?
Edit:
I found out that the following element is blocking the button from beeing clicked:
<svg class="svg-inline--fa fa-spinner-third fa-w-16 fa-spin fa-4x" aria-hidden="true" data-prefix="fas" data-icon="spinner-third" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" data-fa-i2svg=""><path fill="currentColor" d="M456.433 371.72l-27.79-16.045c-7.192-4.152-10.052-13.136-6.487-20.636 25.82-54.328 23.566-118.602-6.768-171.03-30.265-52.529-84.802-86.621-144.76-91.424C262.35 71.922 256 64.953 256 56.649V24.56c0-9.31 7.916-16.609 17.204-15.96 81.795 5.717 156.412 51.902 197.611 123.408 41.301 71.385 43.99 159.096 8.042 232.792-4.082 8.369-14.361 11.575-22.424 6.92z"></path></svg>
Is there a way to wait/stop the script until the elemen/script is gone and continue?
I also tried to wait until the "Subscribe" button is visible but that didn't work:
sbutton = expected_conditions.presence_of_element_located((By.CSS_SELECTOR, 'div.btn.btn-success'))
WebDriverWait(driver, timeout_limit).until(sbutton)
As per the message <div class="delete-overlay white" style="">...</div> is overlapped so the script is not able to click on the <div id="subText" class="btn btn-success">Subscribe</div> button.
Here are the options to handle this situation.
1) Using JavaScript:
ele = WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "'div.btn.btn-success")))
driver.execute_script("arugments[0].click()",ele)
2) Scrolling to Element
ele = WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "'div.btn.btn-success")))
ele.location_once_scrolled_into_view # this will scroll to the element
ele.click()
HTML:
<button aria-expanded="false" class="pv-profile-section__see-more-inline link" data-ember-action data-ember-action-2611="2611">
Python:
buttons = browser.find_elements_by_xpath(u'//button[#class="pv-profile-section__see-more-inline link"]')
print(buttons)
for degree in buttons:
degree.click()
there are two button with the same tag written above but it does not access any of them. It just print the empty list.
The webpage i'm starting from is https://classschedule.tulane.edu/Search.aspx . The page source information for the button I need clicked is:
<input type="submit" name="ctl00$MainContent$btnSearchAll" value="All Courses" id="btnSearchAll" class="JQButton ui-button ui-widget ui-state-default ui-corner-all" role="button" aria-disabled="false" autocomplete="off" style="height: 22px;">
I have tried different methods to find this button and click on it such as;
element = browser.find_element_by_id("btnSearchAll")
element = browser.find_element_by_xpath("//input[#id ='btnSearchAll']")
element = browser.find_element_by_name("ctl00$MainContent$btnSearchAll")
I think it is finding the button because when I do...
print element
...this is returned:
<selenium.webdriver.remote.webelement.WebElement object at 0x2b49690>
I have no other ideas on how to make my program click the button.
I think you didn't add the code for clicking on the element. Please do that and check:
element = browser.find_element_by_id("btnSearchAll")
element.click()
I did try the same code as above with JAVA, and it is working fine.
This works well for me
for i in range(1, 10):
try:
driver.find_element_by_xpath(
f'/html/body/div[{i}]/div/div/div/div/div[2]/span[1]/span/span/input').click()
except:
pass