I have the code
<div>
<input type="radio" id="grupo1" name="grupo1" name="ControlGroupSearchView2$AvailabilitySearchInputSearchView2$RadioButtonMarketStructure" value="OneWay" />
<label>One-way</label>
</div>
And I tried what other suggested to use
args["OW"] = "input[type='radio'][value='OneWay']"
WebDriverWait(self.browser, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, args["OW"])))
self.browser.find_element_by_css_selector(self.args["OW"]).click()
but I get error:
selenium.common.exceptions.TimeoutException: Message:
since it doesn't find the object.
Assuming there are no iframe elements on the page.
What I found working for radiobuttons is to click the corresponding label and not the input:
wait = WebDriverWait(self.browser, 10)
one_way = wait.until(EC.visibility_of_element_located((By.XPATH, "//label[. = 'One-way']")))
one_way.click()
Related
hi i have a element like below:
<input id="txt_search" class="search-box tp-co-1 tp-pa-rl-5 tp-re tp-bo-bo" type="text" placeholder="جستجوی سهم" onmouseup="this.select();" autocomplete="off">
I want to set text of this element to something
so I use below code
element = WebDriverWait(browser, 10).until(
EC.presence_of_element_located((By.ID, "txt_search")))
browser.execute_script("arguments[0].setAttribute('value','something')", element)
so then it should appear a dropdownlist like below but it doesnot
<div id="list_dropdown"><div isin="IRO1PIAZ0001" symbol="غاذر1 - کشتوصنعتپیاذر"><span></span><span style="color: red;">غاذر</span><span>1 - کشتوصنعتپیاذر</span></div></div>
so then i must select first item of this dropdownlist
this is what i want
You have most of the code you need, but there's no reason to use browser.execute_script unless the standard element.send_keys function does not work as expected. Use the below code which leverages your existing code and send_keys function:
element = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID, "txt_search")))
element.send_keys("something")
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.
What is the most recent and up to date way to click "like" on a tweet using selenium?
From the css, it looks like I need to click on this:
<div aria-haspopup="false" aria-label="131310 Likes. Like" role="button" data-focusable="true" tabindex="0" class="css-18t94o4 css-1dbjc4n r-1777fci r-11cpok1 r-1ny4l3l r-bztko3 r-lrvibr" data-testid="like">
That is found on a profile page. My goal isn't to exactly like a tweet on a profile page but If I can figure this out, I'll be able to figure out what I actually want to do.
I have tried a bunch of ways but here are my most recent:
like_btn = (By.XPATH, ("//div[#data-testid='like', #class='css-18t94o4 css-1dbjc4n r-1777fci r-11cpok1 r-1ny4l3l r-bztko3 r-lrvibr']"))
like_btn = (By.XPATH, ("//div[#data-testid='like'"))
copy of Xpath:
like_btn = (By.XPATH, ("//*[#id='react-root']/div/div/div/main/div/div/div/div[1]/div/div[2]/div/div/div[2]/section/div/div/div/div[3]/div/article/div/div[2]/div[2]/div[4]/div[3]/div"))
Copy of full xpath:
like_btn = (By.XPATH, ("/html/body/div/div/div/div/main/div/div/div/div[1]/div/div[2]/div/div/div[2]/section/div/div/div/div[3]/div/article/div/div[2]/div[2]/div[4]/div[3]/div"))
The method then uses:
def like_user_tweets(self, user_tweets=UserStatuses.like_btn):
self.like_btn.click()
It looks like twitter recently revamped everything because even github code from only a year or less ago uses "HeartAnimation" class to find the like button but that doesn't seem to exist anymore.
The error: AttributeError: 'NoneType' object has no attribute 'click'
It is a button so shouldn't it be able to click?
How can I click the like/favorite button?
Error message:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted:
Element <div aria-label="394 Likes. Like" role="button" tabindex="0"
data-testid="like">...</div> is not clickable at point (539, 10).
Other element would receive the click: <div class="css-1dbjc4n r-1habvwh">...</div>
Solution:
browser = webdriver.Chrome()
infoq_url = 'https://twitter.com/infoqchina'
browser.get(infoq_url)
sleep(2)
like_buttons = browser.find_elements(By.XPATH, '//div[#data-testid="like"]')
like_btn = like_buttons[0]
like_svg = like_btn.find_element(By.TAG_NAME, "svg")
like_svg.click()
Reference:
btn_parent = btn.find_element(By.XPATH, "..") # find parent element.
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()
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