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.
Related
I am trying to click on "OK" button on a pop up using selenium and Python but i face an error "no such element: Unable to locate element" although being sure that my id is 100% correct.
> <a class="dxm-content dxm-hasText dx dxalink" href="javascript:;" role="menuitem" id="Dialog_PAC_Menu_DXI0_T"><span class="dx-vam dxm-contentText">OK</span></a>
My python selenium code:
Export2 = driver.find_element(By.XPATH,'//a[#id="Dialog_PAC_Menu_DXI0_T"]')
Export2.click()
Where exactly did I go wrong, i also tried full Xpath, wait till clickable, time sleep. everything!
i would appreciate if someone can help me with it.
Well, it looks like you found the answer and that was because your element was inside an iFrame so I will just post an answer here so others can find an easy answer if they view your question.
tmpheader = driver.find_element(By.CSS_SELECTOR, "#modal > iframe")
driver.switch_to.frame(tmpheader)
Export2 = driver.find_element(By.XPATH,'//a[#id="Dialog_PAC_Menu_DXI0_T"]')
Export2.click()
This switches our current driver that we are looking for into the first iFrame element on the page. If there is more than one iFrame you would need to check for more attributes in the first line to make sure you are looking at the correct one
Actually that's how I solved my issue as my element was inside an iFrame as John Gordon suggested.
driver.switch_to.frame(driver.find_element(By.TAG_NAME,'iframe'))
slider = driver.find_element(By.XPATH,"//*[contains(#id,'_xaf_dviImportExportFormat_Edit_dropdown_DD_B-1Img')]").click()
I am unable to locate a web element on a website, The web elements of the website are dynamic and the elements which i am trying to locate have very similar attributes to that of others with just small differences like changes in integers. These integers also change when i refresh the page so i am unable to locate can someone help?
I tried following but there maybe mistakes in syntaxes:
With contains text = WebDriverWait(browser, 15).until(EC.presence_of_element_located( (By.XPATH,"//div[contains(text(),'Type here...')]") ))
Absolute Xpath and Rel Xpath(these changes)
Contains sibling, contains parents but the parent and sibling elements are also unable to locate
here is the html of the element <div contenteditable="true" class="cke_textarea_inline cke_editable cke_editable_inline cke_contents_ltr placeholder cke_show_borders" tabindex="0" spellcheck="true" role="textbox" aria-label="Rich Text Editor, editor15" title="Rich Text Editor, editor15" aria-describedby="cke_849" style="position: relative;" xpath="1">enter question here</div>
There are spaces being added () which some time cause issue, please deleting that space. Also if you can share html then we might be able to help. WebDriverWait(browser,15).until(EC.presence_of_element_located((By.XPATH,"//div[contains(text(),'Type here...')]")))
I removing space doesn't work then you can try below xpath-
//div[text()='enter question here'][contains(#aria-label,'Rich Text Editor')]
If there are really no attributes you would consider reliable, you can access the element by the text inside of it. I'd recommend two things: Don't do this unless you find no other choice, and don't just use //div, add as much XPATH info to the path as you can.
driver.find_element_by_xpath('//div[text()="enter question here"]')
OR
driver.find_element_by_xpath('//div[contains(text(),"enter question")]')
I'm literally going crazy to find an element in a specific web page. It's an "Enter" button but I haven't been being able to locate it.
ERROR MESSAGE:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"input"}
(Session info: chrome=86.0.4240.111)
I'm going to share with you the possible selectors by ChroPath Extension:
HTML INSPECT CODE "ENTER" BUTTON:
<input type="button" value="Entra" onclick="parent.location.href='site.site.site'">
1°ATTEMPT - PYTHON CODE WITH REL XPATH:
elem = browser.find_element_by_xpath('//body[1]/div[1]/div[1]/div[2]/div[1]/table[1]/tbody[1]/tr[1]/td[2]/table[1]/tbody[1]/tr[3]/td[1]/input[1]')
2°ATTEMPT - PYTHON CODE WITH ABS XPATH:
elem = browser.find_element_by_xpath('/html[1]/body[1]/div[1]/div[1]/div[2]/div[1]/table[1]/tbody[1]/tr[1]/td[2]/table[1]/tbody[1]/tr[3]/td[1]/input[1]')
I have checked if there were any iframes, but I can't find them.
Please, help me.
I agree with #josifoski. It is better to use custom xpath than autogenerated by browser. So in your case try to use the following xpath:
xpath = '//input[#type="button"][#value="Entra"]'
It will be easier to understand and support.
I got it.
I was wrong when I told you that there weren't any iframes in the source code.
There are 2 ones!
So this is the right code to click the "Enter" button:
browser.switch_to.frame(0)
browser.switch_to.frame(1)
elem = browser.find_element_by_css_selector('td:nth-child(2) input')
elem.click()
To figure out, I recorded my steps with Selenium Ide for Chrome Browser, then I exported the python source code and I saw 2 switch_to.frame functions; then I did 2 plus 2...
Like you can see, at the end, I used a css_selector argument based on the recorded source code that I had exported.
I hope it's clear and useful for other people.
Thank you so much for your help and sorry for the incomplete information.
Can you try this
xpath = '//input[#value="Entra"]'
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']")))
This is the button I'm trying to click:
<button class="stkv-c-button stkv-us-button-color--background
stkv-u-background-color-transition-150
stkv-us-button-color--border stkv-us-button-color
stkv-us-button-color--fill stkv-c-button
stkv-c-button--raised stkv-c-button--big">
<span class="stkv-c-button__label stkv-c-button__label--big">Vote Now</span>
</button>
This is the xpath (pulled from Firefox):
[#id='root']/html/body/div/div/div[3]/div/div/footer/div/button"
I've tried a wide variety of ways to click on the button, all to no avail.
self.driver.find_element_by_xpath("//*[#id='root']/html/body/div/div/div[3]/div/div/footer/div/button").click()
self.driver.findElement(By.id("Vote Now")).click()
self.driver.find_element_by_name("Vote").send_keys(Keys.ENTER)
self.driver.find_element_by_id('stkv-c-button stkv-us-button-color--background stkv-u-background-color-transition-150 stkv-us-button-color--border stkv-us-button-color stkv-us-button-color--fill stkv-c-button stkv-c-button--raised stkv-c-button--big').click()
Any suggestions would be greatly appreciated!
I'm not having any luck with it.
You can find the button by display text on it.
locator = "//button[span[text()='Vote Now']]"
self.driver.find_element_by_xpath(locator).click()
Your button doesn't have an id or name, so the find_element_by_name and find_element_by_id methods will not work. find_element_by_class_name seems like the logical choice, but unfortunately it only expects only 1 class, and since your button has multiple classes, it won't work either. I would try locating the button with its CSS selector:
self.driver.find_element_by_css_selector('button.stkv-c-button.stkv-us-button-color--background.stkv-u-background-color-transition-150.stkv-us-button-color--border.stkv-us-button-color.stkv-us-button-color--fill.stkv-c-button.stkv-c-button--raised.stkv-c-button--big').click()
As long as there isn't another button on the page with the exact same CSS selector, this should give you the correct button. In general, if you want to find an element that has multiple classes, e.g. <button class="A B C">MyButton</button>, then you could do it with:
self.driver.find_element_by_css_selector('button.A.B.C')
Use this XPath : //button[normalize-space()='Vote Now']
As per the HTML you have shared to click() on the button with text as Vote Now you can use either of the following solution:
CSS_SELECTOR:
driver.find_element_by_xpath("span.stkv-c-button__label.stkv-c-button__label--big").click()
XPATH:
driver.find_element_by_css_selector("//span[#class='stkv-c-button__label stkv-c-button__label--big' and contains(.,'Vote Now')]").click()