Want to automate twitter's sending images button so I can send a file with python using selenium with the send_Keys method, but can't find its id or name nor class. This is all the code that appears referent to the button:
Html twitter send images button
Note: None of the classes shown above have worked for me
You can try to use x-path, I'm using a chrome extension: https://chrome.google.com/webstore/detail/xpath-finder/ihnknokegkbpmofmafnkoadfjkhlogph?hl=en
To locate the element you want to click.
And then you can use driver.find_element_by_xpath("X-PATH").click()
Related
I am a little bit new to programming but python really made get into it. I am trying to create a programm that automatically checks for updates in a website. I've successfully implemented the neccessary code to call the page of enrollment but yet there is one element that cannot be located. Since I have to do it for multiple courses and iterate throught them there is no specific id, I've tried to find it by title but also this didn't work.
Is there a way you can locate the button with the title "enroll".
I've tried
driver.find_element_by_xpath("//a\[#title ='enroll']").click()
but this didn't work and I always get
NoSuchElement
error.
The XPATH for the button is simply: //*\[#id="id572"\]
Here is the part of the HTML code:
From the screenshot of HTML code you provided, the element is <button>, not <a>.
Try this xpath expression //button[#title='enroll']
This should do it if it's not in any iframes. Just grab the button whose title is enroll and click. Your css selector was an a tag and it might get id dynamically.
driver.find_element_by_css_selector("button[title ='enroll']").click()
I am trying to create a script within Python using Selenium to open a social media page (Tumblr), input user login credentials, and make "quote" posts with a random sentence generator. I am able to input the credentials and select the create post icon using xpaths (driver.find_element_by_xpath) from the website, but when trying input text for the post with the xpath
//*[#id="redpop_iframePostForms"]/div[3]/div/div/div/div/div[2]/div[2]/div/div[2]/div/div[3]/div[1]/div/div[1]/p
using the
self.driver.find_element_by_xpath('//*[#id="redpop_iframePostForms"]/div[3]/div/div/div/div/div[2]/div[2]/div/div[2]/div/div[3]/div[1]/div/div[1]/p').send_keys("It worked!!")
I receive the error
Message: no such element: Unable to locate element: {"method":"xpath","selector":"//div[#id="redpop_iframePostForms"]/div[3]/div/div/div/div/div[2]/div[2]/div/div[2]/div/div[1]/div/div/div[1]"}
I have tried using the other div classes within the list of divs, but I cannot find the correct one. I have also tried using the CSS selector with the code
driver.find_elements_by_css_seletor("div[#aria-label='Quote']").send_keys("It worked!!!")
but that provided the error
Message: invalid selector: An invalid or illegal selector was specified
Any direction on where to go from here?
Thanks!
For no such element exception
From your xpath, i can guess that element is present in an iframe. First switch to that frame and then find element you want to interact with.
For invalid selector message
General Syntax for locating element with css selector is :
tagname[attributeName=‘attributeValue’]
You don’t need to use # with attributeName.
Also, you are fetching all the div elements present in the DOM with aria-label=‘Quote’ and sending keys which is not right. If you want to perform any action on elements, you need to put them in list and then iterate over it. Hope this helps.
I have used python scrapy to extract data from a website. Now i am able to scrape most of the details of a site using scrapy. But my main problem is that iam not able to extract all the reviews of products from the site. I am only able to extract the top 4 reviews which they display on the page and for getting other reviews i have to go to a pop up window which has all the reviews. I looked for 'href' for the popup window but im not able to find it. This is the link that i tried to scrape. The reviews and ratings are at the bottom of the page: https://www.coursera.org/learn/big-data-introduction
Can any one help me by explaining how to extract the reviews from this popup window. Another think to note is that there is infinite scrolling for the pop up.
Thanks in advance.
Scrapy, unlike tools like Selenium and PhantomJS, does not drive a full web browser in the background. You cannot just click a button.
You need to understand what the button does (e.g. does it simply submit a form? Does it do something with JavaScript? Etc.) and reproduce the functionality in your own code.
For example, you might need to read the content of a script element, apply regular expressions to it to pull a URL from a string literal, then make a new HTTP request to that URL, the pell the data you want from the new DOM.
... and then repeat for the next “page” of the infinite scroll.
Issue : - Unable to detect the iframe and switch to iframe as the iframe id and name dynamically changes at each time it loads but the src remain the same.
Unable to identify the xpath as well. Found iframe tag using driver.find_element_by_tagname("iframe") but cant view the tag <iframe> in the HTML of the page source. Therefore unable to find the xpath by right click and iframe tag.
Already tried to find the number of frame size using 'frame.size' but since its not callable, it provide answer in dict which is 'height:0,weight:0'
Require to switch to this iframe and work with the element inside the iframe which is to
1) enter text field into the iframe
2) select radio button in the iframe
Unable to select element after switch to iframe
Screenshot of the code
enter image description here
By default, each frame is assigned an integer number. So you can always do:
driver.switchTo().frame(0)
or
driver.switchTo().frame(1)
You can wait until frame to be loaded as given below.
wait = WebDriverWait(driver, 300)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,'//iframe')))
I was able to answer this, by determining the number of iframe. I've used 'find_element's'_by_tagname('iframe') instead of find_element_bytagname('iframe') which was able to find more than 1 iframe if exist in the page source.
This provides me total 3 iframe tag. Then i proceed to loop into the iframe and find the attribute of the each iframe such as id,name and src.
Then i noticed one of the iframe src, refers to the web address that has the element which i was looking for. Then i proceed to switch to that particular frame using if statement.
Once switch to the iframe, i proceed to get the element.
This solved on how to switch between frame using python-selenium and detect element upon switch the frame.
The key here is to detect on which frame does the element exist within and able to switch to that frame. The frame could be either nested within one frame or list of frame in the main window.
Upon detect and switch the frame. Then would be able to locate the element.
This solves the challenges
Image Attached I want to click on the specific button on a webpage, using selenium webdriver and Python. Tried finding the element by CSS, class name and XPath, but it doesn't seem to work. I have attached an image showing the button I want to click (It is not a dropdown as the image suggests) and the HTML details. Any help would be appreciated.
Actually sometimes selenium is not able to interact with some web elements using click try simulating enter key press on that element for e.g. -
element = driver.find_element_by_id("value")
element.send_keys(:return)
Let me know if that works