This code:
bump = driver.find_element_by_class_name("rlg-trade__action rlg-trade__bump --bump ")
Code
Generates this error:
Unable to locate element:
{"method":"css selector","selector":".rlg-trade__action rlg-trade__bump --bump "}
Error
Here's the HTML code:
HTML Code
Did you notice on the error message that Selenium appended a . to the class name. So doing this:
driver.find_element_by_class_name("rlg-trade__action rlg-trade__bump --bump ")
Made Selenium look for an element which matched this selector:
.rlg-trade__action rlg-trade__bump --bump
When what you wanted was something like this:
.rlg-trade__action.rlg-trade__bump.--bump
If you look the documentation up, it seems that find_element_by_class_name only allows you to find an element by a single classname.
So if you really want to go around this by using that selector, maybe find_element_by_css_selector makes more sense:
driver.find_element_by_css_selector('.rlg-trade__action.rlg-trade__bump.--bump')
Related
<div class="writtingArea _editor" contenteditable="true" placeholder="보낼 메시지를 입력하세요."></div>
it is element that i needed to find and send chat but if i try to find this with this line of code,
driver.find_element_by_class_name("writtingArea _editor").click()
it gives me error that says it couldn't locate element. So i tried to locate it by Xpath. but it didn't work either.
How can i fix this??
Since there is a space between two class names you are not able to call that class names merged.
Please try below line to find and click that element.
driver.find_element_by_css_selector("div.writtingArea._editor").click()
I have navigated to a (https://gmet.edupage.org/) webpage, logged in and got to the final step to complete my code, which is to click a next day arrow which cycles through the days of a calendar. Thing is while I have done this many times before the program still returns an error selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"next.fa.fa-angle-right"}
I wonder why cant it get the element when the source webpage code looks like this:
<span class="next fa fa-angle-right" data-smer="1" style="display:inline-block"></span>
My code looks like this:
next_page_button = driver.find_element_by_x('.next.fa.fa-angle-right')
next_page_button.click()
Any ideas on why this migh not work?
this should work:
next_page_button = driver.find_element_by_xpath("//span[#class='next fa fa-angle-right']")
next_page_button.click()
The issue was pretty simple I just had to add a time.sleep command so that the page has time to load.
I am trying to scrape the target website for product_links. The program should open the required URL in the browser and scrape all the links with a particular class name. But for some reason, I am getting a NoSuchElementException for this piece of code
links = driver.find_elements_by_class_name("styles__StyledTitleLink-mkgs8k-5")
for link in links:
self.driver.implicitly_wait(15)
product_links.append(link.find_element_by_css_selector('a').get_attribute('href'))
I tried printing out the text in each link with link.text in the for loop. The code is actually selecting the required elements. But for some reason is not able to extract the href URL from each link. I am not sure what I am doing wrong.
This is the entire error message
NoSuchElementException: Message: no such element: Unable to locate
element: {"method":"css selector","selector":"a"} (Session info:
chrome=83.0.4103.106)
Error seems there is no css element with 'a' so you need to try with other locators to identify elements. try with xpath=//a[contains(text(),'text of that element')]
You are looking for a class name generated by a builder, check the random string at the end of the class name, these classes won't be found in every web.
if you want to scrape them, find a different generic class or find all classes with a subset string "StyledTitleLink"
Here's how to do it with JQuery
You should try and find a different solution to your problem
I'm testing my web scraping skills with Python and Selenium and I found an button with a changing "id" "ember" and the numbers change everytime. Everything else is the same as all buttons. The only thing that's unqiue is
<button aria-label="View only People results" id="ember697" class="search-vertical-filter__filter-item-button artdeco-button artdeco-button--muted artdeco-button--2 artdeco-button--tertiary ember-view" type="button"><!---->
<span class="artdeco-button__text">
People
</span></button>
I've tried all the methods so far (i.e., id, CSS_selector, xpath, etc.).
[![Linked In button][1]][1]
Here's the error I keep getting no matter what I select.
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element
So, since you want to search through aria-label, you can use an XPATH:
driver.find_elements_by_xpath("//button[#aria-label='View only People results']")
EDIT: You could also use a css selector like this:
driver.find_elements_by_css_selector("button[aria-label='View only People results'']")
Try this:
option1 - i am assuming ember will be there and only numbers are changing
driver.find_elements_by_xpath("//*[starts-with(#id, 'ember')]")
option 2-
driver.find_elements_by_xpath("//*[contains(#id, 'ember')")
option 3-
driver.find_elements_by_xpath("//*[contains(#class, 'search-vertical-filter__filter-item-button')")
Hope it helps you.
I'm trying to crawl review data on an app from a Google Play website page using Python and Selenium. What I'm trying to do here is to click the "Full Review" button to see the entire text of each review.
But I keep running into these errors each time:
ElementNotInteractableException: Message: element not interactable
or
AttributeError: 'list' object has no attribute 'click'
or
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".LkLjZd ScJHi OzU4dc "}
The element for the button is this:
<button class="LkLjZd ScJHi OzU4dc " jsaction="click:TiglPc" jsname="gxjVle">Full Review</button>
The xpath for the button is this:
//*[#id="fcxH9b"]/div[4]/c-wiz/div/div[2]/div/div[1]/div/div/div[1]/div[2]/div/div[26]/div/div[2]/div[2]/span[1]/div/button
And this is the code I'm using for xpath:
full_review = driver.find_elements_by_xpath('//*[#id="fcxH9b"]/div[4]/c-wiz/div/div[2]/div/div[1]/div/div/div[1]/div[2]/div/div[26]/div/div[2]/div[2]/span[1]/div/button')
full_review.click()
I can't find the button by class name, xpath or anything.
Could anyone help me figure out this problem? In addition, is it possible to find the element by jsname?
I would really appreciate if you could help.
Avoid using xpath whenever possible, it's the most brittle selector.
id > CSS > Xpath
For your button, this css selector should work:
button[jsname='gxjVle']
You'll probably need to specify the child as that probably won't be unique
Your XPath selector is a little bit flaky, you can simplify it to be something like:
//button[text()='Full Review']
You're using the wrong function, if you're looking for a single unique element you should be using WebDriver.find_element_by_xpath one, mind that element, not elements
It's better to use Explicit Wait just in case element is not immediately available in DOM (for example if you're testing application built using AJAX technology)
Assuming all above:
full_review = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Full Review']")))