I am trying to retrieve the page name of each page on a site. The steps are the following:
Click on the settings icon
a Modal Dialog Box appears (That is what I believe they are called?). The Dialog Box appears for three seconds before closing.
Click on "Rename Page"
A Popup- window appears with a text field (containing the page name). The popup also contains the buttons "Ok" and "Cancel
Retrieve the name in the text field
Press Ok
Go to the next page. Repeat stages 1-4
For some reason at stage 2, seemingly at random, I receive a TimeOutException error. I say at random, because the error occurs on sometimes on say, the 55th page and sometimes 130th page and so on. I believe it might be because the dialog box closes, before the Rename Page button has been clicked (Which is weird since 3 seconds should be ample time to click on the button.
Screenshot
I am using the framework Spyder to write code in. When the TimeOutException occurs, if I run the code from Step 1. Everything works again without error. So for some reason, sometimes the error occurs and sometimes not.
The HTML code for the Settings Icon is the following:
<div
id="_labsfluxbar_WAR_labsfluxbarportlet_showCurrentPageSettingsPopupButton"
class="labs-fluxbar-portlet-current-page-settings-popup">
</div>
The HTML code for 'Rename Page'
<ul
class="labs-fluxbar-portlet-page-menu-items">
<li class="labs-fluxbar-portlet-page-menu-item labs-fluxbar-portlet-page-menu-item-rename" title="Rename this page"
onclick="_labsfluxbar_WAR_labsfluxbarportlet_renamePage('9398653')"> Rename page
</li>
The code in Python:
i = 0
while True:
#Get page name
# Step 1 - Click on Settings icon
settings = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "_labsfluxbar_WAR_labsfluxbarportlet_showCurrentPageSettingsPopupButton"))) #Search for settings button
settings.click() #click settings icon
# Step 2 - Click on the "Rename Page" button
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[#class='labs-fluxbar-portlet-current-page-settings-popup-content']//li[#title='Rename this page']"))).click() #Click on the Rename page element
# Step 3 - Retrieve page name from text field
page = driver.find_element_by_xpath("//input[#id='popup_prompt']")
page_name = page.get_property("value") #Copy the name of page
print(page_name)
# Step 4 - Click ok to close PopUp window
driver.find_element_by_xpath("//input[#id='popup_ok']").click() #Exit the popup window
# Step 5- Go to the next page
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "_labsfluxbar_WAR_labsfluxbarportlet_pageDropdownList")))
select = Select(driver.find_element_by_id('_labsfluxbar_WAR_labsfluxbarportlet_pageDropdownList'))
select.select_by_index(i)
i += 1
The TimeOutExcpetion (sometimes) occurs after running the following line, however I don't get why?
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[#class='labs-fluxbar-portlet-current-page-settings-popup-content']//li[#title='Ange ett nytt namn för sidan']"))).click()
Does anyone have any suggestion what is occurring, or what could be done to prevent it?
Embarrassingly the issue was not due to the code.. It was because of a bad/slow internet connection.
Related
I am working on 3 webpages (Let say Page A to C) with Python Selenium.
Both Page A and B contain this button:
<button id="continue-button" type="button" class="form-button" data-autom="button-label"><span>Click</span></button>
When clicking this button on Page A, it will jump to Page B; When clicking it on Page B, it will jump to Page C
I use the following code to perform auto click action on Page A, it works great.
element_confirm = driver.find_element("id", 'continue-button')
driver.implicitly_wait(5)
driver.execute_script("arguments[0].click();", element_confirm)
However, when I execute above code (different element name) again on Page B, nothing is happened.
No error message is on the log. I tried to print some text after driver.execute_script. It shows normally. I tried to find the element with "xpath", '//*[#data-autom="button-label"]', also no clcik action is performed. Checked the element is True (It means it can be found).
100% confirm that Page A to C are working fine when I click the button manually (using my mouse). Any recommendation?
Thank you!
Update:
As requested, this is the code that I use for Page B:
element_submit_two = driver.find_element(By.ID, 'continue-button')
driver.implicitly_wait(5)
driver.execute_script("arguments[0].click();", element_submit_two)
Aren't you using outdated selenium? According to docs, you should use like that:
from selenium.webdriver.common.by import By
button = driver.find_element(By.ID, "continue-button")
button.click()
I am a total noob that tries to get together a code that will do below things.
1.) Log in with my credentials to the page https://www.alza.sk/EN/
2.) Refreshes the page in a specific interval, for example "60 seconds"
3.) Checks for the “In stock” text on any product displayed or a specific one product that will be opened in the one browser tab"
4.) Click on the “Add to cart” button beside the specific product that will be opened in the mentioned one browset tab and continue to the shopping cart by clickiny on “Proceed to Checkout” button, afterwards click on “Continue” button, if popup window displays with two buttons “Do not add anything” and “Add the selected items to your cart“ then click on the first button “Do not add anything”. In the next page choose the “Bratislava - main shop” checkbox and after that choose “Confirm your selection” button in the popup window. Afterwards click on “All payments option” section so all options are displayed and choose the “Cash / Card (when collected) checkbox. After that click on “Continue” button. And this is the step when i need to login by entering my credentials. So this i”ll update later today. But i suppose it would be best to log in in the Step 1.) as i described.
This is all i could so far get together, but i am unable to add all i described, so it will work.
from selenium import webdriver
import time
import urllib
driver = webdriver.Chrome()
driver.get("https://www.alza.sk/EN/")
while(True):
driver.refresh()
time.sleep("60")
from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get("input url here")
expected_text="Available"
actual_text=driver.find_element(By.XPATH, '//button[text()="Available"]').text
while actual_text!=True:
driver.refresh()
time.sleep(input time interval here)
if expected_text==actual_text:
actual_text=True
driver.find_element(By.XPATH, '//button[text()="Available"]').click()
#add other steps
This is just a suggestion on how to proceed with the script. If you can update the question with the URL and proper code, it will be easier to give a proper solution.
I am creating a downloader from Instagram. This program gets URLs from top Instagram posts in a given hashtag and inputs them into a downloader. The issue is that a popup iframe ad always appears over the download button when the website is first loaded. This throws an error that the button cannot be clicked because the iframe will be clicked.
This is for Python Selenium running Chrome driver. I have tried to run a filter that finds iframes and goes back to the main page:
all_iframes = self.browser.find_elements_by_tag_name("iframe")
if len(all_iframes) > 0:
self.browser.switch_to.default_content()
This did not work, I also tried to get the XPath to the X-button on the ad, but the ID changes every time, so I cannot be clicked or identified.
#get the website
for link in self.links:
self.browser.get('https://downloadgram.com/')
time.sleep(5)
#this is the x button click iframe I tried, but the XPath changes
all_iframes = self.browser.find_elements_by_tag_name("iframe")
if len(all_iframes) > 0:
xButton = self.browser.find_element_by_xpath('//div[#id="id3019a64023cross3019a64023"]')
xButton.click()
#inputs the URL from array links[] into download box
input = self.browser.find_element_by_xpath('//input[#name="url"]')
input.clear()
input.send_keys(link)
time.sleep(1)
#clicks download button
download = self.browser.find_element_by_xpath("//input[#type='submit']")
download.click()
time.sleep(1)
#clicks confirm button
actuallyDownload = self.browser.find_element_by_xpath("//a[#target='_blank']")
actuallyDownload.click()
time.sleep(1)
I expect the code to download the pictures at the url, but I get:
selenium.common.exceptions.WebDriverException: Message: unknown error: Element <input type="submit" value="Download" class="button"> is not clickable at point (451, 446). Other element would receive the click:
the website (turn off adblock to see add) https://downloadgram.com/
I am able to close the pop up with following code.Please try that.
browser.get('https://downloadgram.com/')
time.sleep(5)
element=browser.find_element_by_xpath("//div[starts-with(#id,'id')]" and "//div[starts-with(#style,'position:absolute !important;height:20px !important;width:20px !important;top:3px !important;left:3px !important;background-image:url(data:image/png;')]")
arrt=element.get_attribute("id")
print(arrt)
browser.execute_script("arguments[0].click();", element)
Let me know if it works.Good Luck.
I'm trying to automate an e-commerce website, after i click 'add to cart' a lightbox will be displayed for user to proceed to view cart and to continue to check out.
Here is my sample code, i think my code doesn't find the button because the lightbox is still loading.
driver.find_element_by_id("qty").send_keys("4")
driver.find_element_by_class_name("add_to_cart_btn").click()
Lightbox loading here
driver.find_element_by_class_name("button_primary").click() #for clicking the view cart
driver.find_element_by_link_text("Proceed to Checkout").click()
use the explicit wait method
element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.Classname, "add_to_cart_btn")))
element.click();
I am trying to click a button/element on a popup window using Selenium 2 Library in Robot framework, but I get an error.
This is the code:
Test Click Like
Wait Until Page Contains Element //iframe[#title="Facebook Social Plugin"]
Select Frame //iframe[#title="Facebook Social Plugin"]
#Frame Should Contain //*[#id="u_0_0"]/div/div/div[2]/div[1]/a/img[#src="https://www.facebook.com/rsrc.php/v1/yi/r/odA9sNLrE86.jpg"]
Click Element xpath=//*[#id='u_0_0']/div/div/div[3]/div[1]/div[2]/div/div[2]/div/div[2]/a[1]/em/*[#data-intl-translation="Thích"]
Sleep 5s
Capture Page Screenshot
Wait Until Page Contains Element xpath=//*[#id='u_0_0']/div/div/div[3]/div[1]/div[2]/div/div[2]/div/div[2]/a[1]/em/*[#data-intl-translation="Bỏ thích"]
Sleep 5s
Capture Page Screenshot
This is the error:
Error
ValueError: Element locator 'xpath=//*[#id='u_0_0']/div/div/div[3]/div[1]/div[2]/div/div[2]/div/div[2]/a[1]/em/*[#data-intl-translation="Thích"]' did not match any elements.
I have this HTML code:
<a href="#">
<em class="_4qba" data-intl-translation="Thích" data-intl-trid="">Thích</em>
</a>
You have to select that pop-up window first for performing any actions on that opened pop-up window.