Python Selenium Clicking a javascript Radio Button - python

I am right at the end of my script and this must be the last page I have to go through and I am stuck. I have spend 3hrs with different combination and different methods trying to load the elements.
the page is heavly javascript so when I try and get page source it gives me
This page uses frames, but your browser doesn't support them.
I have identified there are two frames inside the window and tried to apply all the attempts against both frames.
The result when I try and select to the frame
**driver.find_element_by_xpath('''//*[#id="three"]/tbody/tr[2]/td/div[2]/a/input''').click()**
error
**Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[#id="three"]/tbody/tr[2]/td/div[2]/a/input"}**
i have also tried the below with or without the [0] on all frames still the same issue
**driver.find_element_by_xpath('.//input[#type="radio" and #value="05"]')[0].click**
I have tried this but also get the same error
**element = driver.find_element_by_id("reason")**
Below is a screenshot of the code in the inspector window.
screenshot of inspector

try to switch to the containing frame first:
parent_frame=driver.find_element_by_css_selector('your selector')
driver.switch_to.frame(parent_frame)
#select the button after
How to identify and switch to the frame in selenium webdriver when frame does not have id

Try with driver click on radio button
element = driver.find_element_by_xpath("//table[#id="three"]//input[#name="reason"]")
element.click();
or javascript executor
element = driver.find_element_by_xpath("//table[#id="three"]//input[#name="reason"]")
driver.execute_script("arguments[0].click();", element)

Related

Python_Selenium_ng click button is not working using xpath

I am unable to click on Open button, below is the element... getting timeout exception error.. Note: there are multiple open buttons with same class..want to click on 1st one
Open
tried with xpath too(//*[#id="reportHeaderCol4NonMobile"]/div[2]/div[3]/div[3]/fieldset/div[1]/div[1]/div/button[1])
no such element error with xpath
here is thescreenshot of inspect element
Absolute xpath is always fragile, use the below xpath to identify and click.
This will click the first button of your many Open buttons as you have mentioned.
openbutton=wait.until(EC.element_to_be_clickable((By.XPATH,'(//button[text()="Open"])[1]')))
openbutton.click()

Xpath in RobotFramework - element not found error

I am using RobotFramework(new to it) to access https://auth0.github.io/device-flow-playground/ and then click the Get Started button on this page.
My code:
open browser https://auth0.github.io/device-flow-playground/
click button xpath://*[#id="start-btn"]
But I am getting this error :
Button with locator 'xpath://*[#id="start-btn"]' not found.
Just can't seem to figure out what is wrong here when the xpath is given correctly. Any pointers please?
I'm not familiar with RobotFramework, however looks like you are missing a delay.
You need to wait for the element you want to click to be visible first and only after that to click it.
So, your code could be something like this:
Open Browser https://auth0.github.io/device-flow-playground/
Wait Until Element Is Visible xpath://*[#id="start-btn"]
Click Element xpath://*[#id="start-btn"]
The answer is
Open Browser https://auth0.github.io/device-flow-playground/
Wait Until Element Is Visible xpath://*[#id="start-btn"] 10s
Click Element xpath://*[#id="start-btn"]
You can increase the wait time as you needed.
And as well as if there is multiple elements of button cross check if you add as argument as needed below
Click Element xpath:(//*[#id="start-btn"])[1]
Argument can be changed as per your need.
Click Button only works for button elements. What you're trying to click on is a div , so you need to use Click element instead:
Click Element xpath://*[#id="start-btn"]

Unable to click on an element after switching to frame in Selenium

I am unable to click on an element after switching the focus to the correct frame. The frame does not have name/id attributes. Switching to frame was ok, but 'TimeoutException' was given when I added click command.
I have tried various ways:
Explicit wait
Tried different XPATHs
submit() instead of click()
send_keys(Keys.RETURN) instead of click()
Used ActionChains class to move to element and click on it

How to click the Continue button on website using selenium in python?

I am trying to write a code that is able to auto apply on job openings on indeed.com. I have managed to reach the last stage, however, the final click on the application form is giving me a lot of trouble. Please refer the page as below
Once logged in to my profile, I go to the relevant search page, click on the listing I am interested in and then on the final page (shown above) I am trying to click on the continue button using xpath as follows:
driver.get("https://in.indeed.com/jobs?q=data%20analyst&l=Delhi&vjk=5c0bd416675cf4e5")
driver.find_element_by_xpath('//*[#id="apply-button-container"]/div[1]/span[1]').click()
driver.find_element_by_xpath('//*[#id="form-action-continue"]')
However, this gives me an error:
Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[#id="form-action-continue"]"}
Having gone through some suggestions on the net I have even tried the following:
driver.get("https://in.indeed.com/jobs?q=data%20analyst&l=Delhi&vjk=5c0bd416675cf4e5")
driver.find_element_by_xpath('//*[#id="apply-button-container"]/div[1]/span[1]').click()
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[#id="form-action-continue"]')))
But then this gives me a timeout error
TimeoutException: Message:
Will appreciate some help on this.
From it seems, on that form there are multiple iframes, therefore the reason for your errors.
You need to get the first iframe, switch to it, get the second iframe inside the first one, switch to it and only afterwards you'll be able to get the continue button.
Something like this should do the trick:
frame_1 = driver.find_element_by_css_selector('iframe[title="Job application form container"')
driver.switch_to.frame(frame_1)
frame_2 = driver.find_element_by_css_selector('iframe[title="Job application form"]')
driver.switch_to.frame(frame_2)
continue_btn = driver.find_element_by_css_selector('#form-action-continue')
continue_btn.click()
Once I had a similar issue and standard time.sleep() until the form (or continue button) appears helped me. Try it instead of WebDriverWait, maybe it will work.

Locate "file upload" button with Selenium

I have the button shown below (image and HTML) and am trying to click it.
Selenium is unable to locate it - I have tried locating by both xpath and by ID.
<input id="wsUpload1" type="file" name="file">
XPATH:
element = driver.find_element_by_xpath('//input[#id="wsUpload1"]')
element.click()
Where am I going wrong?
EDIT: Here is the exception thrown by Selenium:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[#id="wsUpload1"]"}
Possibilities
Duplicate web element with same id in the page.
Element may be in frame. You need to switch to frame
Trying to access the web element before page is loading.Give some wait time.
Not sure why your button wasn't found, maybe it's because of quotes (although it should show you error in that case), try with driver.find_element_by_xpath(".//input[#id='wsUpload1']") and see if it works. I'm not sure is your button already rendered on the page or you trigger it somehow so it's not there yet?
NoSuchElementException is thrown because your targeted element couldn't be found on that page, it could be that you are on the wrong page, element is not rendered yet so you should wait for it to appear, element could be in some iframe etc etc, it's hard to say when I don't know how your page works.
But if you are trying to upload something you should perform sendKeys() on that button (with path of file which are you trying to upload), not click() on it. This is how selenium upload works.
I have solved it - the driver opens a tab on a side panel and the button is in the tab. There seems to be a few ms delay between clicking the tab and the button appearing so I added a wait until element is clickable and that seems to work.
wait.until(EC.element_to_be_clickable((By.XPATH, "//input[#id='wsUpload1']"))).click()

Categories