I have just started learning Selenium and was playing around a bit trying to automate a search on the secondhand clothing website vinted.fr.
I was able to find all necessary Elements in the HTML code, except one: -The Button to change the "sort by" functionality to "newest". (
This is a Screenshot of the Page including the Button I want to press)
Now I am wondering, what the Problem might be:-Is it possible, that the button is not having a "button" tag in the HTML code. If yes how do I find and click this element?-Am I just searching at wrong position?
Here is the HTML source code where I suggest the button element to be in:
To click on the element to set sort by functionality to newest you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:
Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "ul.pile li:nth-of-type(4) label"))).click()
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//ul[#class='pile']//li[#class='pile__element'][last()]//label"))).click()
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Related
I'm currently working on a project with Selenium and webdriver. So far so good I can navigate through the website using selenium without any problem however, I would need to click on a specific icon to slides through to a date and time table. Issue is when looking at the HTML I have no idea what to locate with Selenium in order to click on that icon.
HTML sample:
<a _ngcontent-oyt-c155="" class="btn btn-soft-primary day-selector-navbutton"><i _ngcontent-oyt-c155="" class="fa fa-chevron-right"></i></a>
Usually I'm locating items by name, ID or Class but in that case I don't know where to got with.
Should I look for the xpath instead ?
Accordingly to what you have shared here this XPath should work:
'//a[#class="btn btn-soft-primary day-selector-navbutton"]//i[#class="fa fa-chevron-right"]'
I can't be completely sure if this locator is unique or if there is no iframe there etc.
You will possibly need to add some kind of wait here too. If so you should preferably use Expected Conditions explicit waits.
The desired element is a Angular element, so to click() on the clickable element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:
Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.btn.btn-soft-primary.day-selector-navbutton > i.fa.fa-chevron-right"))).click()
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[#class='btn btn-soft-primary day-selector-navbutton']/i[#class='fa fa-chevron-right']"))).click()
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
I have been stuck on this issue, where no matter how i write out the navigation to the specific element, using .click() wont work, the element 100% loads in before the click is fired(this i know because i can manually click it), but it wont actually click, is there something about ng-click that needs specification or what, but hopefully i can atleast get some closure as to why this element wont be clicked
<div class="item-card-thumb-container" ng-click="root.onItemCardClick(userAsset)">
is there any possible way to click this element without specifically finding that element and adding .click() to it, because it doesn't seem to work, I understand its too vague, but also maybe the element isn't clickable unless the mouse hovers over the element, cause it is a UI
The desired element is a Angular element element, so ideally to click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:
Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.item-card-thumb-container[ng-click^='onItemCardClick']"))).click()
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[#class='item-card-thumb-container' and contains(#ng-click, 'onItemCardClick')]"))).click()
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
I'm trying to make fill a feedback form ( actually it is attendance ) automatically with python. I'm able to traverse through all the pages but every page has different value and id for "Present" it is kind of dynamic
Is there a way I can find "Present" radio button on the page. I don't have much knowledge of html
P.S. I've read the question on stackoverflow already but the answer were not able to solve it will still give me error
This xpath should find your input tag based off the Present tag.
//span[text()='Present']/preceding::input
By it's class
//input[class='form-check-input ']
To click on the element with text as Present you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following xpath based Locator Strategies:
Using index:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[#class='statusdesc' and text()='Present']//preceding::input[1]"))).click()
Using attributes:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[#class='statusdesc' and text()='Present']//preceding::input[#class='form-check-input ' and #name='status']"))).click()
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
I cant click on a button on a webpage using selenium. Does anyone know how i can click it, I've tried every single method i can think of and i cant quite get it to work.
I've tried XPATH, ID's, searching for the text on the button, i've tried copy pasting code from other people.
This is the button i want to press:
<div id="sbWatchHeaderNext">
Next
</div>
This is the code I currently have that isn't working:
WebDriverWait(driver, 3).until(EC.presence_of_element_located((By.XPATH, "//button[contains(text(),'Continue Watching')]")))
and
driver.find_element_by_xpath("//button[contains(text(),'Next')]").click()
Please if you have any suggestions i should try, let me know :)
With some methods i would get absolutely no errors in console but nothing would happen on the webpage, and with others i would get "Message: no such element: unable to locate element:..." and things like that in my console.
Seems you were pretty close. To click() on the desired element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following solutions:
Using LINK_TEXT:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Next"))).click()
Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div#sbWatchHeaderNext>a[href^='https://pf.entertainow.com//f/p/enter?plid']"))).click()
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[#id='sbWatchHeaderNext']/a[starts-with(#href, 'https://pf.entertainow.com//f/p/enter?plid') and text()='Next']"))).click()
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
I am pretty new to Python and Selenium, and I have got my script to do what I want so far, but I have this current coding from the website:
<a onclick="realPostBack('ctl00$ctl00$mainContent$ContentPlaceHolder1$ucHub$ucSearchExplorer$dgContents$ctl00$ctl04$lnkContent', ''); return false;" id="ctl00_ctl00_mainContent_ContentPlaceHolder1_ucHub_ucSearchExplorer_dgContents_ctl00_ctl04_lnkContent" class="hub-content-item" actiontype="Secondary" href="javascript:__doPostBack('ctl00$ctl00$mainContent$ContentPlaceHolder1$ucHub$ucSearchExplorer$dgContents$ctl00$ctl04$lnkContent','')"><span>How to Project Wirelessly in Philly</span></a>
and I can't get it to click the link.
I've tried:
driver.find_element_by_text("How to Project Wirelessly in Philly")
and partial text
driver.find_element_by_id("ctl00_ctl00_mainContent_ContentPlaceHolder1_ucHub_ucSearchExplorer_dgContents_ctl00_ctl04_lnkContent")
I've tried by tag but all returning errors. Looking up on here, I've seen stuff with Xpath but I have no clue how to do that, but if someone here does, then a little help with that, or any other simple code that hopefully allows me to click that link. (I know i will have to do .click() to eventually click it, but i cant even find the element yet)
The desired element is a dynamic element, so invoke click() on it you have to induce WebDriverWait for the element to be clickable and you can use either of the following solutions:
Using CSS_SELECTOR:
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.hub-content-item[id*='SearchExplorer'][actiontype='Secondary']>span")))
Using XPATH:
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[#class='hub-content-item' and contains(#id,'SearchExplorer')][#actiontype='Secondary']/span[text()='How to Project Wirelessly in Philly']")))
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC