Selenium Unable to Get Link of Image inside iframe > iframe > img - python-3.x

I am facing an issue in getting element using selenium python.
Element wrap inside two iframes tags. Hierarchy given below
iframe > iframe > a
xpath manually working fine. But using selenium it giving me error given below
//img[contains(#href,'google')]
Thanks in Advance

You need to 'switch' into the iframe, Selenium has the built-in switch_to method for this.
Example: driver.switch_to.frame('frame_name')
You can read the documentation for more help and examples.

Related

Sending text to text box using Selenium in Python

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.

How can I get the inspect element HTML Selenium

I'm trying to get a HTML that is not the page_source, I need the one that is generated when you open the page.
I have seen and tried all the solutions I could find but nothing really works.
I do not need any code since I do not know how to do it. I have tried with page_source but I need the inspect element HTML.
Could someone explain a good example with this?
From Get current HTML of rendered page using Selenium I suggest you using
self.driver.find_element_by_xpath("//html").get_attribute('outerHTML')

Cannot find element within iframe using Selenium

I'm trying to locate elements within the iframe but got no luck.
I think because of my code cannot switch to the iframe and that's why I couldn't locate the elements within it.
Below is my code.
I have tried
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, '/html/body/iframe')))
driver.find_element_by_name('applicant.name').send_keys('email')
I also tried this
iframe = driver.find_element_by_xpath('/html/body/iframe')
driver.switch_to.frame(iframe)
driver.implicitly_wait(10)
driver.find_element_by_name('applicant.name').send_keys('email')
I tried look for xpath, id of the applicant.name but notthing work so far. Any help or suggestions would be appreciated.
Here the site:
https://www.indeed.com/cmp/Paratus-Partners-LLC/jobs/Full-Stack-Developer-7814e52be25090f3?from=iaBackPress&q=software%20developer&vjs=3
There are at least 2 iframes in the page you're trying to automate:
Therefore you need to
Amend your XPath Expression to uniquely identify first iframe like:
parentIframe = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH,"//iframe[contains(#id,'modal-iframe')]")))
Switch to first iframe
driver.switch_to.frame(parentIframe)
Locate second iframe and switch to it
childIframe = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH,"//iframe[contains(#src,'resumeapply')]")))
driver.switch_to.frame(childIframe)
Once done you should be able to send text into the input fields.
There are some elements with the xpath /html/body/iframe
I was looking for the applicant.name and it was only to create after click on the postulate button.
I think that you have to check the xpath for the iframe, maybe something like this can work
"//iframe[contains(#src,'resumeapply')]"

Python Selenium Webdriver: No Such Element or Element not Visible or InvalidSelectorException

I am trying to access an button in browser with the Name export via selenium web driver. I have tried with the xpath
driver.find_element_by_xpath("//div[#class='tb-btn']//[contains(text(), 'Export')]").click() for this i get the error InvalidSelectorException.
when i tried driver.find_element_by_xpath("*//[contains(text(), 'Export')]").click() for this i get the error Element Not Visible.
When i tried driver.find_element_by_xpath("*//[#id="master_btnExport"]").click() i get No such Element.
This is the image of the url when inspect the element
Not sure why i get these errors. Any inputs would be really helpful.
Regards,
Ren.
Try either of following two Xpath.It should work.
driver.find_element_by_xpath("//a[#id='master_btnExport']")
Or
driver.find_element_by_xpath("//a[#class='tb-btn-0link-left']")
If you want to give some time to load for element to be available try that.
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[#id='master_btnExport']")))
OR
WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//a[#id='master_btnExport']")))
Hope this helps
This error occurs when you either give a wrong path to an element or your script runs before actually letting that element load

Unable to click on the link using selenium and Python

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

Resources