On web-page there is button, which describe by code below:
<button onclick="getListRating(1); return false;" class="button is-gray pagination__more">Open</button>
Need to click by use selenium lib - first i tried to find as "css_celector" but it didn't work:
allm=driver.find_element(By.CSS_SELECTOR, 'button is-gray pagination__more') # Find button
allm.click() # Click!
What find class i need to use to click this button?
I'd find the button by the onclick attr. Here is a solution with xpath.
button = driver.find_element_by_xpath('//button[#onclick="getListRating(1); return false;"]')
button.click()
Related
Here is the HTML Code:
<div class="ui-helper-hidden-accessible">
<input type="radio" name="group2" value="yes">
</div>
Full script
Here are the code which i've tried to click the radio button:
driver.find_element(By.CSS_SELECTOR, 'input[name= "group2"][value="yes"]').click()
AND
rdbutton = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'input[name= "group2"][value="yes"]'))).click()
AND
rdbutton = driver.find_elements(By.XPATH, "//input[#name='group2']")
for rdbuttons in rdbutton:
if rdbuttons.is_selected():
pass
else:
rdbuttons.click()
It seems that you are using wrong locator. From the HTML you have given i think you are trying to click on radio button that have label Ya if this is the case then try with below xpath:
"//label[contains(text(),'Ya')]"
OR
"//*[normalize-space()='Ya']"
If this does not solve your problem, so please explain and add HTML of proper element either by screenshot or in textual format
When I enter my account and make request to the invite link and turns out that invite link expired, selenium correctly determines the button "Continue to Discord":
button = driver.find_element_by_css_selector("[type='button']")
But when invite is still valid, selenium can't determine button "Accept Invite". Codes of these both buttons:
<button type="button" class="marginTop40-i-78cZ button-3k0cO7 button-38aScr lookFilled-1Gx00P colorBrand-3pXr91 sizeLarge-1vSeWK fullWidth-1orjjo grow-q77ONN"><div class="contents-18-Yxp">Accept Invite</div></button>
<button type="button" class="marginTop40-i-78cZ button-3k0cO7 button-38aScr lookFilled-1Gx00P colorBrand-3pXr91 sizeLarge-1vSeWK fullWidth-1orjjo grow-q77ONN"><div class="contents-18-Yxp">Continue to Discord</div></button>
Why can't selenium find first button if their codes are actually the same? I tried almost all methods. By xpath, by css selector and by class. Nothing helped. Seems like changing browser doesn't help too. Any ideas?
<paper-radio-button name="NOT_MADE_FOR_KIDS" class="style-scope ytcp-audience-picker iron-selected" role="radio" tabindex="0" toggles="" aria-checked="true" aria-disabled="false" aria-selected="true" checked="" active="">
<div id="radioContainer" class="style-scope paper-radio-button">
<div id="offRadio" class="style-scope paper-radio-button"></div>
<div id="onRadio" class="style-scope paper-radio-button"></div>
<paper-ripple id="ink" center="" class="circle style-scope paper-radio-button" checked="">
I am trying to select the 'No, it's not made for kids' option when uploading a video to youtube,
I do
kids_box = driver.find_element_by_name('NOT_MADE_FOR_KIDS')
kids_box.click()
Also tried with class name and id, I tried clicking the id='onRadio' too. Any help on this is appreciated!
You are just clicking to the button as a whole and I think it is wrong.
Instead, you should be clicking to the desired option on the radio button. In order to do this, please try the code snippet below.
kids_box = driver.find_element_by_id('onRadio')
kids_box.click()
If the above solution does not work, what you should be doing is, right click to the option circles in the radio button, then click inspect in Google Chrome, then right click to the button again and then click inspect again.
After completing this progress, you will see the corresponding line of the radio button. Right click to it, select copy, then select copy xpath and use the function below:
kids_box = driver.get_element_by_xpath("//div[#id='a']/div/a[#class='click']")
kids_box.click()
You should paste the xpath to inside the parantheses.
I cannot create the .click()-action on the button.
HTML:
<button class="btn__type btn__type_close">Закрыть</button>
I try to make an element clickable for execute_script:
driver.execute_script("return document.getElementsByClassName('.btn__type_close')").click()
My code using Selenium:
driver.find_element_by_css_selector('button.btn__type_close').click()
None of the methods is working.
Question: How will it be correct?
Did you try clicking using XPath?
WebElement btnClose=driver.findElement(By.xpath("//button[#class='btn__type btn__type_close']"));
if(btnClose.isEnabled()){
btnClose.click();
}
I'm trying to click on this button: browser.find_element_by_id('btnSearch')
But this button is blocking by this div tag: <div id="actionSearch" class="row pull-right">
How do I go around to click this button with id='btnSearch" while it's blocking by the actionSearch div?
I tried the following:
browser.find_element_by_id('btnSearch').click()
browser.implicitly_wait(10)
el = browser.find_element_by_xpath('//*[#id="btnSearch"]')
ActionChains(browser).move_to_element_with_offset(el, 1827, 270)
ActionChains(browser).click()
ActionChains(browser).perform()
element = browser.find_element_by_id('btnSearch')
browser.execute_script("arguments[0].click();", element)
wait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, //*[#id="btnSearch"]'))).click()
none of these work.
Can anyone help me with this? I've spent two days trying to click this button!! Please help!
Considering provided image of HTML source (tip: do not provide it as image, but as text instead) I can assume that required element located in the bottom of page and you might need to scroll page down to be able to handle it.
Try below code
link = browser.find_element_by_id("btnSearch")
browser.execute_script("arguments[0].scrollIntoView()", link)
link.click()
Note that link is not a pseudo-element (is not located inside ::before/::after pseudo-element), so it can not be the cause of your problem
As for your code:
ActionChains(browser).move_to_element_with_offset(el, 1827, 270)
ActionChains(browser).click()
ActionChains(browser).perform()
Here you're trying to make scroll to link with huge offset and then you make click on current mouse position - not on link
You can try to modify it as
ActionChains(browser).move_to_element(el)
ActionChains(browser).click(el) # Pass WebElement you want to click as argument to `click()`
ActionChains(browser).perform()