How to Click hidden span[role="checkbox"] in selenium - python-3.x

I can click hidden span tag checkbox using playwright codegen.
Here is the code:
page.frame_locator("iframe[role=\"presentation\"]").locator("span[role=\"checkbox\"]").click()
But How Can I do the same thing using selenium?
I am trying this but It's not working for me
driver.find_element(By.XPATH, "//iframe[#role='presentation']").find_element(By.XPATH, "//span[#role='checkbox']").click()
Could anyone please help me.
Thanks

Related

Selenium Unable to Get Link of Image inside iframe > iframe > img

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.

How to choose a radiobuttton without id with selenium webdriver and VBA

I am trying to automate the navigation of a website. I cannot choose a radio button using the methods I know so I hope someone can guide me. Here is the html:
I have tried different versions of
bot.FindElementByClass("css-k2m43g-RadioWrapper ewsdbue1").Click
bot.FindElementByClass("css-njdfi2-NativeRadio ewsdbue3").Click
bot.FindElementByClass("css-34xfl3-CustomStyledRadio ewsdbue2").Click
but that crach the VBA.
Any suggestions?
Try css attribute = value selector
bot.FindElementByCss("[type=radio]").click

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

Python 3 - Click a line in a pulldown menu only visible with mouse-over

I am trying to automate the process of logging into a website and downloading reports.
When choosing which report to download you have to mouse over a menubar on the website and hovering the mouse over the right tab will open a pulldown menu where you then click the report you want.
Screenshot of the pulldown menu (sorry, but no points embed the image :( )
I have little experience with coding and I am very new to Python 3 so I am struggling on how to do this.
Using Selenium library I am able to find things such as the user and password fields and pass in the information to automatically log into the site. But not sure how to grab or point at the correct report in this pulldown menu in order to simpy click it.
Here is a snippet of the page source... the class name = rmText... and the class name is same for all of them... only the text inside the <span> is unique but I don't know how to grab that with the Python 3 code.
Screenshot of the page source
I know of a way to do this using VB script... but I would prefer to stay with Python 3 (and also learn how to do this via Python in the process). The example below was used for a similar report where multiple lines had same class-name and we needed just the one called "Infill". An example code of the VB script:
Set project = .Document.getElementsByClassName("UPC_Items")
For Each elm In project
If instr(elm.innerhtml,"Infill") then
elm.Click
Exit For
End If
Next
How can I achieve the same using Python 3? And is Selenium the right library to use?
Thanks for reading and hopefully helping out a newbie in Python!
try below code, hope this helps:
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
drive = webdriver.Firefox()
driver.get('your url')
....
steps to reach your place where that menu link is presert
....
element = driver.find_element_by_class("rmText")
putmouse = ActionChains(driver).move_to_element(element)
putmouse.perform()
time.sleep(2)
texttoclick = driver.find_element_by_xpath(".//li[#class='rmText']//span[text()='MCC']")
actions.move_to_element(texttoclick).click().perform()

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