I am trying to get an element from a website and I would get this error:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[2]/div[3]/div[1]/div[1]/button"}
I got the element by copying the XPath in inspect element and made sure the element exists and is clickable. Here is my code:
driver.find_element_by_xpath("/html/body/div[2]/div[3]/div[1]/div[1]/button").click()
Here is the HTML code:
<button class="styled joinRound" data-text="joinGame">Join game</button>
How can I fix this?
It may be easier to test if you include the URL you’re working with.
You can try finding it by text instead:
driver.find_elements_by_xpath("//*[contains(text(), 'Join game')]").click()
Click button by text using Python and Selenium
This may also help. It’ll record your clicks and may give you the right path you need.
https://chrome.google.com/webstore/detail/katalon-recorder-selenium/ljdobmomdgdljniojadhoplhkpialdid?hl=en-US
Related
HTML code for the button I want to click
Can anyone please help me, I'm trying to tell selenium to click a button on a website I'm trying to automate. Ive attached a picture of the HTMl code that I want the Webdriver to click.
Can anyone tell me the best find element option to use to click the button.
Ive looked into Xpath but can't seem to get it working?
Thanks
<use xlink:href="#icon-menu-more" href="#icon-menu-more"></use>
So I was trying to grab the xPath from this line of code.
the Xpath is /html/body/div/div[1]/header/nav/button[1]/span[1]/svg/use
but then when trying to use driver.find_element_by_xpath() i get an error saying unable to locate element.
You can try
driver.find_element_by_id('icon-menu-more')
this will help you to click the button
Other Options are
driver.find_element_by_name('name of element')
driver.find_element_by_class_name('class name of element')
driver.find_element_by_tag_name(tag name of element)
driver.find_element_by_css_selector('css selector of element')
Im a beginner in python and selenium, Ive been trying to make selenium click on the dropdown menu. Ive tried alot of solutions but none worked.
picture
This is my code
driver.get('chrome://settings/content/siteDetails?site=https%3A%2F%2Fmeet.google.com%3A443')
time.sleep(3)
microphone = driver.find_element_by_xpath("//select[#aria-label='Microphone']")
This is the error
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate
element: {"method":"xpath","selector":"//select[#aria-label='Microphone']"}
Is there anything i did wrong?
This element is located inside multiple shadow-roots.
See here for more details how to deal with shadow DOM.
I have this website where I want to get the element post-title.
I tried driver.find_element_by_class_name("sc-1di2uql-1 vYcWR") but that just returns: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".sc-1di2uql-1 vYcWR"}
I have seen similar posts where the problem was that the searched element was in an iframe but I cant see anything like that here. Then again I started to learn about webscraping about a week ago so theres probably a lot I dont know.
I had a similar issue with selenium before. My problem was that the website would rotate class names, so every time you access the page they would be different. Judging by the way the class names are on your website I think you have the same issue. If this is the case, you are just trying to look for something that is not there. What I did to solve this problem was using driver.get_element_by_xpath(“PASTE FULL XPATH OF THE ELEMENT”) instead of finding the element using its css class.
To get the full path of an element: in the developer tools, right click on the element and click copy FULL XPATH.
i need to click second row submit buttonI am trying to use the XPath of the tab present on the website and collected XPath using chrome/firefox but it seems that every time I am getting an exception as below:
I have kept sleep time and can see website loading pretty early than the sleep time still getting the errors.
said_input = driver.find_element_by_xpath('//*[#id="ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder3Col_txtSubmitCase"]')
print(said_input)
said_input.send_keys(said)
exception:
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: [id="ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder3Col_txtSubmitCase"]
One thing is that i have navigated to another page of website by clicking one of the menu button will this driver.find_element_by_xpath will be able to locate it. if not how can i do so in case if i hae to browse through multiple pages and fill few forms.
I want to type text, and send it like showed in the following link
example of form to be filled out.
I am however unable to type anything in the field. I supposed at first it was an iframe, but splinter is unable to locate it. If i search by tags for the body, it says that:
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot focus element
How might i go about fixing this?
if your element is not focused you have to first move to that element using selenium actions as following:
first move to using ;
driver.switch_to.frame(driver.find_element_by_css_selector("#inquiry-content_ifr"))
Then focus on element
yourElement= driver.find_element_by_css_selector(".nav")
actions = ActionChains(driver)
actions.move_to_element(menu)
actions.perform()
then do your interaction with that element after focus has been set to the element.