I am working on a problem where I need to enter data into a form in a iFrame.
The problem is that the iframe does not have an ID or name. It is the
first iframe (or frame) on the page, so I was planning to get a list
of the frames on the page and select the first one in the returned
list. I have done something simliar with windows
ie:
order_window = page.driver.browser.window_handles[0]
page.driver.browser.switch_to.window(order_window)
can something similar be done with frames?
if so how?
cucumber (1.0.6)
Capybara (1.1.1)
selenium-webdriver (2.5.0)
Related
I am trying to scroll Telegram using selenium in python. In the attached screenshot I have shared I have selected 'Members' as the element to send Keys.PAGE_DOWN as it is stick all the time to top and is static while scrolling so it should be visible all the time and can be the perfect element to send Keys.PAGE_DOWN to.
But on sending page_down I get error 'Element not Interactable'.
Any suggestions what I am doing wrong?
I have attached the script and screenshot.
I am using python 3.10 and selenium latest version.
`driver.find_element(By.XPATH, "//*[#id='RightColumn']/div[2]/div/div/div[2]/div[2]/div[1]").send_keys(Keys.PAGE_DOWN)`
I have tried all the answers currently available on the internet and they don't work here. This looks like some complex issue.
I think Selenium is throwing the right error message as this div is not an interactable element and you are trying to send keystrokes into the element.
Another approach for scrolling is using Javascript commands.
Find an element locator you need to scroll to.
(Ex: if you need to scroll to the bottom find the element at the bottom)
Use the below code to scroll
# Find the element in the page to scroll to
element = driver.find_element_by_xpath("//element/at/bottom/of/the/page")
# Fire javascript command to scroll in to view
driver.execute_script("arguments[0].scrollIntoView();", element)
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 learning Python and attempting to build a program that will scrape specific data from a website, store it and then manipulate it.
Currently I run my application, it opens a new chrome browser window and loads the page correctly. The problem is it should begin to start scrolling down and loading the remaining elements on the page.
I know the code works because if I manually click somewhere on the page that doesn't normally illicit a response (white space/empty areas) the browser somehow comes into "focus" and begins to iterate through the loop that scrolls down the page (by sending keys) prints the data I am after. I also noticed if I click another similar "dead space" area that contains the header, it doesn't have the same effect. I am unsure if this is something specific to Chrome, iFrames or something of that nature but I am completely stumped and would greatly appreciate any help.
Any thoughts on why I need to manually click on the new chrome window for it to work would be great.
Update: Still having the same issue, even tried with Safari and the same problem seems to exist.
Fixed this with:
element = driver.find_element_by_css_selector("div[id^='app-container']")
action = ActionChains(driver)
action.click(on_element = element)
action.perform()
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