Hope you´re fine,
Please! Hope you can support me with this topic.
I tried lot of ways to try to click this button by Selenium but I couldn´t. The error is that Selenium cannot locate the object.
ERROR MESSAAGE: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath", "selector":"//*[#id='C47_W166_V167_thtmlb_button_2']"}
Here The python code to make click:
window_before = driver.window_handles[0] #Save Current window
window_after = driver.window_handles[1] #Identify new raised window
driver.switch_to.window(window_after) #To go to new raised window
time.sleep(3)
driver.maximize_window()
driver.switch_to.frame("WorkAreaFrame1popup")
print(driver.title)
time.sleep(3)
ALL_BRANDS_BTN= driver.find_element_by_xpath("//*[#id='C51_W184_V185_thtmlb_button_2']")
ALL_BRANDS_BTN.click()
I made the same for other buttons on the same web tool without any issues, but for this particular button I can´t. Maybe I´m missing something?
I already put extra waiting time but neither worked.
Im attaching an image of the element inspection. Please, hope you can help me,
Thanks in advance
<span class="th-bt-span"><b class="th-bt-b">All Brands</b></span>
<span class="th-bt-span"><b class="th-bt-b">All Brands</b></span>
As you have mentioned you have used same kind of code for other buttons So I am assuming you are in correct window and iFrame. If not please insure your button is in correct windoe and frame.
Can you try below code to click your button:
btn = WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.XPATH, "//b[text()='All Brands']//ancestor::a"))) #Used Text instea of Id , as not sure if ID is dynamic or not
driver.execute_script("arguments[0].scrollIntoView();", btn ) #Scroll to button
driver.execute_script("arguments[0].click();", btn ) #Click then button
Related
I'm new to using Selenium with Python. I'm trying to click on this sign-in button on glassdoor: Glassdoor Sign-in Button
Actual: Using both the XPATH and the classname "LockedHomeHeaderStyles__signInButton", I keep getting the "ElementNotInteractableException" thrown.
Expected: I should be able to select the element and click it.
When I open the site and try to manually click the button myself, I am able to do this. Am I doing something wrong in my code?
def sign_in():
sign_in_element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CLASS_NAME, "LockedHomeHeaderStyles__signInButton"))
)
sign_in_element.click();
There are two button element with "Sign In" text. You need second one. Try using the below xpath-
//button[text()="Sign In" and not(contains(#class,"d-flex"))]
I'm trying to locate a element, but I can't click on it. The id is ("save-all-conditionally"), but it's not working if I click on it. I tried css.selector, xpath and all other things, but nothing is working!
There are 2 frames, frame inside frame.
You would need to switch to parent frame then child frame.
here is the working code :
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.maximize_window()
driver.get("https://www.gmx.net/consent-management/")
driver.implicitly_wait(10)
firstFrame = driver.find_element_by_xpath("//iframe[#class='permission-core-iframe']")
driver.switch_to.frame(firstFrame)
driver.switch_to.frame(0)
driver.find_element_by_xpath("//button[#id='save-all-conditionally']").click()
Try this code, see if it works:
ele = driver.find_element_by_xpath("//*[#id='save-all-conditionally']")
ele.click()
Not tested yet:
iframe = driver.find_elements_by_tag_name('iframe')
if len(iframe) == 1:
driver.switch_to.frame(iframe[0])
button = driver.find_element_by_id('save-all-conditionally')
if button:
button.click()
Since the iframe has no id get it by tag name, it should be one iframe use switch_to.frame to switch to the iframe content and get the button to click on it
i'm trying to click the "download Results" button on this website .
i'm using below python code to click this button
from selenium import webdriver
chromedriver_path = 'E:/software/python/chromedriver'
url = 'https://www.cms.gov/apps/physician-fee-schedule/search/search-results.aspx?Y=0&T=4&HT=2&CT=3&H1=74750&H2=74800&M=5'
driver= webdriver.Chrome(executable_path=chromedriver_path )
driver.get(url)
driver.find_element_by_xpath('//*[#title="Download Results"]').click()
i'm getting below error
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//frame[#name="aspnetForm"]"}
(Session info: headless chrome=83.0.4103.116)
i'm thinking if the button is within a iframe but how do I find out the iframe?
This may help you out: Unable to locate element using selenium webdriver in python
Try and switch to the frame first, and then search for the element.
i realized that there's a agreement page that i need to click 'Agree' button first.
i didn't see this in browser because i already clicked 'Agree' weeks ago. but in webdriver, i need to click that each time.
Just after the URL opens, a page comes up asking you to agree the terms. You need to click on that Agree first. Since it is possible that once clicking on the Agree button, it won't come again if you accepted it on default browser. So just be sure with code, you can first check the presence of the agree button first.
This kind of function you may make to check presence:
def elementPresent(locatorType, locator):
#present = true
#not present = false
wait = WebDriverWait(driver, 20)
try:
wait.until(EC.presence_of_element_located((locatorType, locator)))
except Exception:
return False
return True
And then using if condition you may proceed further like:
if(elementPresent("xpath", "//a[#title='Accept']/span")):
driver.find_element_by_xpath("//a[#title='Accept']/span").click()
and then you may click on the element you want, there is no frame that is required to be switched to.
driver.find_element_by_xpath("//a[#title = 'Download Results']/span").click()
Just extract the element and click on it and your required file will be downloaded.
I am trying to use Selenium to click the button highlighted above. I have no problem locating the element via:
download_button_path = "//button[#class='btn-primary']"
download_button = driver.find_element_by_xpath(download_button_path)
However when I try and execute:
download_button.click()
I get the error message:
ElementNotVisibleException: Message: element not interactable
(Session info: chrome=70.0.3538.67)
(Driver info: chromedriver=2.42.591059 (a3d9684d10d61aa0c45f6723b327283be1ebaad8),platform=Mac OS X 10.11.6 x86_64)
It seems the button is not visible to selenium even though I am able to see it when performing the click manually.
I have also tried to hover over the button and then click, as well as send an Enter/Return key to the button, but nothing is working.
Any insight would be appreciated.
In the HTML, I see the btn-primary is present in a bootstrap modal popup. So there may another btn-primary behind the modal pop. The XPath will be finding the element which is behind the modal which is not interactable.
btn-primary class is a generic class in bootstrap that will be used in all primary buttons. Try with unique locator with reference to modal element as a parent in your locator
download_button_path = "//[#class='lmn-edititem-modal']/../[#class=''btn-primary']"
wait = WebDriverWait(driver, 10)
download_button = wait.until(EC.visibility_of_element_located((By.XPATH, download_button_path)))
download_button .click()
We can also try this with CSS selector
driver.find_elements_by_css_selector(".lmn-edititem-modal .btn-primary")
For me, extending relative Xpath just with its parent helped.
button = driver.find_element_by_xpath("//button[#data-value='0']")
button.click()
#this did not work
button = driver.find_element_by_xpath("//section[2]/button[#data-value='0']")
button.click()
#this worked well
Have you tried hovering over the button and then clicking?
try the following:
button_to_click = driver.find_element_by_xpath('button_to_click's xpath')
hover = ActionChains(driver).move_to_element(button_to_click)
hover.perform()
button_to_click.click()
Hope this helps.
I want to get a link in a popup window of this page.
http://stivconsultasexternas.cnbv.gob.mx/ConsultaInformacionEmisoras.aspx
Clicking the first link that appears the page show us a popup window. I like to get the link inside of thin window.
Here is my code. I appreciate any help.
from selenium import webdriver
import time
driver = webdriver.Firefox()
driver.get("http://stivconsultasexternas.cnbv.gob.mx/ConsultaInformacionEmisoras.aspx")
link=driver.find_elements_by_partial_link_text(u"Verum")
time.sleep(5)
link[0].click()
time.sleep(5)
print driver.page_source.encode("utf_8","ignore")#Here I want a html of a popup window.
Thank you so much.
The problem you're running into is that the popup is in an iframe. Selenium can only access the current content, anything in a child iframe is inaccessible. In order to allow Selenium to access the new iframe, you'll need to use switch_to.frame:
link[0].click()
time.sleep(5)
driver.switch_to.frame("DefaultPlaceholder_callbackPanel_Popup_CIF-1")
print driver.page_source.encode("utf_8","ignore")#Here I want a html of a popup window.
driver.switch_to.default_content()
driver.find_element_by_xpath("//td[#id='DefaultPlaceholder_callbackPanel_Popup_HCB-1']").click()
Edit #1:
I looked at the page, and found the popin you wanted to access was contained in this iframe:
<iframe id="DefaultPlaceholder_callbackPanel_Popup_CIF-1" title="" src="/Detalle.aspx?enc=vxwQ2MoMebbVt2C93KNYJA%3d%3d" scrolling="auto" frameborder="0" style="height: 578px; width: 100%;">
switch_to.frame() can accept the following as an identifier:
- The name or id of the iframe. I used this particular case, since the iframe in question has id="DefaultPlaceholder_callbackPanel_Popup_CIF-1"
- The index of the iframe. That would looks something like switch_to.frame(0)
- The iframe element. You could find the iframe element via a find_element_by_ locator, then use the webelement result of that in switch_to.frame(el)
Edit #2:
To close the dialog, you need to use switch_to.default_content(), as the close button is outside of the iframe. You can then click the close button of the dialog, and proceed. See the last line in the code above, that line should close the dialog for you.