<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.
Related
I am trying to web scraping a popular movie database on the Internet. After a few thousands of requests, my spider is detected and I have to manually click on a simple button to continue my data collection.
I have tried to automatize this process by clicking automatically in that button. For that purpose, I am using Selenium library. I have located the xpath of the button, but, for some reason, .click() method doesn't work.
Here is my code:
def click_button():
options = Options()
options.headless = True
options.add_argument("--window-size=1920,1200")
DRIVER_PATH = 'geckodriver'
driver = webdriver.Firefox(options=options, executable_path=DRIVER_PATH)
driver.get('https://www.filmaffinity.com/es/main.html')
element = driver.find_element(By.XPATH,"//input[#value='Send']")
element.click()
driver.quit()
Also, I have tried other common alternatives, such as waiting until the element gets clickable or visible, but this didn't work. I have also tried to execute the click as a javascript script.
This is the window I see when my spider is detected:
Too many request window (picture)
As you see, there is a reCaptcha-protection icon on the lower right corner, but I don't have to solve any captcha puzzle to confirm I am not a robot, I have just to click on the send button you can see on the picture.
The html which contains the button is the following one:
<div class="content">
<h1>Too many requests</h1>
<div class="image">
<img height="400" src="/images/too-many-request.jpg">
</div>
<div class="text">
Are you sure you do not dream of electric sheep?
</div>
<form name="toomanyrequest">
<div class="alert">
please enter the Captcha to continue.
</div>
<div>
<input type="submit" value="Send">
</div>
</form>
</div>
Which do you think is the trouble with my code or approach? I have to find a way to click on that button to continue my scraping, but I don't know what I am doing wrong (I have little experience at this field).
Maybe the xpath is not correct? Maybe the captcha protection is blocking the click action? I don't get any exception when I execute my code; but nothing happens and the "Too many request" window does not disappear.
Thank you very much.
Try this:
driver.execute_script("arguments[0].click()", element)
or:
driver.execute_script("arguments[0].click();", element)
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?
<a class="btn btn-xs btn-success" href="/user-location-auth/location?id=4013"
title="View User Location Access" data-toggle="tooltip" data-method="post">
<span class="glyphicon glyphicon-map-marker"></span></a> <span
class="glyphicon glyphicon-map-marker"></span> <<pseudo:before>>
</<pseudo:before>>
Hi all, I have been tasked with a project that requires clicking on a button in a table (with 14 cells). The first 13 cells are all unhidden, but the 14th one (where the buttons are located), are hidden unfortunately. I have tried action chains, I have tried hovering over the element and then clicking on it. I seem to be at a loss here. This piece of code did work, however I want to avoid using javascript as I want to replicate a user experience.
z4 = driver.find_element_by_css_selector('a.btn-success > span.glyphicon-map-marker')
driver.execute_script('arguments[0].click();', z4)
Hi everyone and cruisepandey, I found a solution that works. First, I waited for the presence of the element to be located. Once that occurred, I grabbed the element and moved to it with ActionChains (I think I was misusing ActionChains earlier). Then I was able to click on the Bootstrap button.
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, """
//tr[#data-key='2312312321321']/td/a[contains(#class, 'btn-xs btn-
success')]/span[contains(#class, 'glyphicon')]""")))
y = driver.find_element(By.XPATH, """//tr[#data-
key='2312312321321']/td/a[contains(#class, 'btn-xs btn-
success')]/span[contains(#class, 'glyphicon')]""")
#Use action chains to click on the button
ActionChains(driver).move_to_element(y).click().perform()
I was doing some web scraping with python (Linkedin site) and got stuck with the following 2 issues: 1) How do I input text on a search bar? 2) How to click a button? First, this is the search bar code:
<input aria-autocomplete="list" autocomplete="off" spellcheck="false"
placeholder="Búsqueda" autocorrect="off" autocapitalize="off" id="a11y-
ember6214" role="combobox" class="ember-text-field ember-view" aria-
expanded="false">
To input the text I was using the xpath (and it works) but it changes every time I login into the site:
search = driver.find_element_by_xpath('//*[#id="a11y-ember997"]')
search.send_keys('MedMake')
So could I use instead part of the input bar code above so that I can rerun my script multiple times?
My second point is 2) how to click a button. Again I was using the xpath but it changes after every login. My code was:
button = driver.find_element_by_xpath('//*[#id="nav-search-controls-wormhole"]/button')
button.click()
I inspected the button code and I would instead like to use data-vertical="PEOPLE" or any other of this unique fields (the tag button is not enough since there are many buttons on Linkedin site). By the way,how are all these inner fields called? I believe part of my problem arises from the lack of html code understanding.
<button data-vertical="PEOPLE" data-control-
name="vertical_nav_people_toggle" data-ember-action="" data-ember-
action-8620="8620" data-is-animating-click="true">
Gente
</button>
If id attribute values are dynamic you can use other attributes with static values:
search = driver.find_element_by_xpath('//input[#placeholder="Búsqueda"]')
search.send_keys('MedMake')
button = driver.find_element_by_xpath('//button[normalize-space()="Gente"]')
button.click()
First one use xpath
//input[contains(#class,'ember-text-field')]
Second one use the xpath
//button[#class='vertical_nav_people_toggle']
I was implementing a bot to click on upvote button in reddit
Here is the html code of the upvote button.
<div class="arrow up login-required access-required" data-event-action="upvote" role="button" aria-label="upvote" tabindex="0"></div>
<div class="score likes">•</div>
<div class="score unvoted">•</div>
<div class="score dislikes">•</div>
<div class="arrow down login-required access-required" data-event-action="downvote" role="button" aria-label="downvote" tabindex="0"></div>
I am able to click on the upvote button using
target = driver.find_element_by_xpath("//div[#class='arrow up login-required access-required']")
target.click()
OR
target = driver.find_element_by_css_selector("div.arrow.up")
target.click()
The clicking works fine in FIREFOX web driver , but when I try to implement the same in PhantomJS , the browser is not clicking.
Here is the screenshots of 2 browsers
Try performing click() operation via jQuery or JavaScript using execute_script method of selenium. Below is the sample code that will perform the click operation.
driver.execute_script("$('div.arrow.up').click()")
For the page which has multiple upvote fields then you can use an index to choose which one you want to click e.g
driver.execute_script("$('div.arrow.up')[0].click()")
driver.execute_script("$('div.arrow.up')[1].click()")
driver.execute_script("$('div.arrow.up')[2].click()")
and so on..