Trying to get the result for the Website
I am not getting any error while clicking on Go button but the result also does not get refreshed. Can any one please help in this.
I tried few ways to click on Go but not working:
driver.find_element_by_xpath('//div[#class="col-sm-1 text-right"]/button[#class="btn btn-primary amfi-btn"]').click()
driver.find_element_by_xpath('//button[. = "Go"]').click()
driver.find_element_by_xpath(".//button[#class='btn btn-primary amfi-btn']").click()
driver.find_element_by_css_selector('[class="btn btn-primary amfi-btn"]').click()
driver.find_element_by_xpath('//button[normalize-space()="Go"]').click()
driver.find_element_by_xpath('//button[. = "Go"]').click()
driver.find_element_by_xpath(".//button[#class='btn btn-primary amfi-btn' and #type='submit']").click()
Related
I am trying to create a for loop which:-
1) clicks the dropdown item
2) add a comment
3) submit a comment
This whole loop will happen in the same page itself. The XPath is correct and I can execute these lines individually once but it fails in a loop. What am I doing wrong here?
No particular error message given
add_comments = driver.find_elements_by_class_name('add')
comments = driver.find_elements_by_xpath("//form[#class='addComment expand']//textarea[contains(#placeholder,'Add a comment')]")
submit_comments = driver.find_elements_by_xpath("//button[text()='Comment']")
i = 0
for add_comment in add_comments:
for comment in comments:
for submit_comment in submit_comments:
WebDriverWait(driver, 5)
add_comment.click()
comment.click()
comment.send_keys("Awesome Art")
WebDriverWait(driver, 2)
submit_comment.click()
i += 1
if i > 4:
driver.close()
Link is https://society6.com/society?show=2 but might not work since its within my account. Here is the screenshot
The '+add comment is the part where i want to put comment
Html is here-
<form class="addComment expand" data-id="9647336">
<img src="https://ctl.s6img.com/society6/img/g2taHIrokQ01R_67jS8ulaWI2wk/h_150,w_150/users/avatar/~artwork/s6-original-art-uploads/society6/uploads/u/sul97/avatar_asset/d837ee10016843a3bba9ae3310cc338d" width="25" height="25">
<textarea placeholder="Add a comment..." data-button="9647336"></textarea>
<button id="b9647336">Comment</button>
</form>
I'm using Python and Selenium. My problem is that I can't switch on the modal that pops out and I can't click the buttons in it.
This is the elements of the modal:
This is my code:
minus the url of course
browser = webdriver.Chrome(executable_path="D:\\sasdsa\\automate\\chromedriver_win32\\chromedriver.exe")
user_name = browser.find_element_by_xpath("//input[#id='username']")
user_name.send_keys("test.employee")
##Password
pass_word = browser.find_element_by_xpath("//input[#id='password']")
pass_word.send_keys("123")
##log_in = browser.find_element_by_css_selector(".btn")
log_in = browser.find_element_by_xpath("//button[#class='btn btn-sm btn-primary btn-block']")
log_in.click()
##punch
#driver.find_element_by_id("//#id='product_view')
#To open the modal
punch_in = browser.find_element_by_xpath("//button[#class='btn btn-success btn-sm pull-right']")
punch_in.click()
#cant switch to the modal to access the button
browser.switch_to_frame("product_view")
punch_in2 = browser.find_element_by_xpath("//button[#id='save_me']")
punch_in2.click()
Delete the line below and it should work fine.
browser.switch_to_frame("product_view")
You don't need to do anything special here. A modal dialog like this is just HTML like any other HTML on the page. You access it just like you would anything else.
Having said that... if you click a button, etc. that launches the dialog, you will probably have to add a WebDriverWait to wait for the dialog to be visible before accessing elements inside it, etc.
Andersson and JeffC are right. I had a similar issue. I treated the modal window as something different, which didn't work by the way. At the end, I just treated it in the usual way. I simply added browser.implicitly_wait(60) after initiating the browser, and it worked.
What Jeff said worked for me. I had
<div class="ReactModalPortal">
I just added sleep for 3 seconds to see if it was working. It worked.
Then I used :
act = ActionChains(self.driver)
act.send_keys(Keys.TAB).perform()
act.send_keys(Keys.ENTER).perform()
I'm having an issue clicking on an image using the Chromedriver with Selenium for the following HTML:
<div class="modal_buttons">
<input type="image" name="GoButton" id="GoButton" tabindex=14 title="Continue" alt="Continue" onfocus="SetLastFocus(this.id)" src="https://t4.ftcdn.net/jpg/00/81/83/05/240_F_81830511_aJbF2vH9yufF0UAUFQ83JDnbp0jE5mNV.jpg"
I tried using the following code:
element = driver.find_element_by_css_selector("//div[img/#src='https://t4.ftcdn.net/jpg/00/81/83/05/240_F_81830511_aJbF2vH9yufF0UAUFQ83JDnbp0jE5mNV.jpg']").click()
Selenium is failing everytime, and giving the same list of errors that it can't locate the button. Any ideas how to fix?
Thanks
Try:
driver.find_element_by_xpath("//input[#id='GoButton'][#name='GoButton']").click()
or
driver.find_element_by_xpath("//input[#id='GoButton'][#title='Continue']").click()
or
driver.find_element_by_xpath("//input[#name='GoButton'][#title='Continue']").click()
or
driver.find_element_by_xpath("//input[contains(#src,'240_F_81830511_aJbF2vH9yufF0UAUFQ83JDnbp0jE5mNV.jpg')]")
I am testing a textbox and button - the user types in some information to the textbox and then hits the button - the button changes text from "Update" to "Updating" and then back to "Update" once the operation is complete.
I want Selenium to wait until the button returns back to "Update" before continuing.
I have tried various solutions using xpath here is where I am now:
self.wait.until(EC.element_to_be_clickable(By.XPATH, '//button[#id="send_data"][text()="Update"]'))
The HTML of the button is as follows:
<button id="send_data" type="button" class="btn btn-success" onclick="ChangeParam(this,'radio','freq'; return false;">Update</button>
and
<button id="send_data" type="button" class="btn btn-default" onclick="ChangeParam(this,'radio','freq'; return false;">Updating</button>
Where am I going wrong?
This is quite common issue: you should send type_of_locator, "locator_string" as tuple of arguments ((By.XPATH, "//button")), but not as two separate args (By.XPATH, "//button")
Use following code
self.wait.until(EC.element_to_be_clickable((By.XPATH,'//button[#id="send_data"][text()="Update"]')))
Another solution that should work is using EC.invisibility_of_element_located. After clicking Update button, you can wait invisibility of Element which represented of "Updating" state button.
self.wait.until(EC.invisibility_of_element_located((By.CSS_SELECTOR,'button#send_data .btn-default')))
I am trying to click a button that brings up a dialogue box to select a file. inspecting the element it looks like its an input rather than a button. Either way I cannot click it with:
element = browser.find_element_by_id("fileupload")
element.click()
and
browser.find_element_by_id("fileupload").send_keys("\n")
Neither of which seem to work.
Here is what I see when I inspect that element on the page:
<span class="btn btn-success fileinput-button">
<span class="glyphicon glyphicon-upload"></span>
Select and Upload...
<input id="fileupload" name="upfile" accept=".xml" type="file">
</span>
Any assistance help or pointers would be appreciated!
Clicking on a file input usually triggers a file upload dialog. Since you cannot control it with selenium, you need to avoid the dialog being opened by sending keys to the input instead:
browser.find_element_by_id("fileupload").send_keys("path_to_the_file")
See also:
How to deal with file uploading in test automation using selenium or webdriver
How to upload file using Selenium WebDriver in Java
How to upload file ( picture ) with selenium, python