I am trying to check whether the 'Add to cart' button exists or not on the webpage [Ebuyer][1]
Using Chromedriver.
I have tried a few things including:
driver.find_element_by_xpath("/html/body/section/div[1]/div[3]/div[1]/div[3]/form/input[2]")
driver.find_element_by_class_name("button--add-to-basket")
The problem is that it just cant seem to find the button, any help will be greatly appreciated!
[1]: https://www.ebuyer.com/809813-corsair-ll-series-ll120-rgb-120mm-3-fan-pack-co-9050072-ww?_sgm_campaign=scn_8714e1eb7e000&_sgm_source=809813&_sgm_action=click
If you mean Add to Basket button, use CSS Selector:
driver.find_element_by_css_selector(".js-add-to-basket-main.js-show-loader")
Using css selector works.
css = 'input.button.button--add-to-basket' driver.find_element_by_css_selector(css)
Related
I'm trying to click buttons on amazon with selenium (python) but it won't work. It says the elements don't exist. I tried to google it but only found outdated solutions. I've tried Xpaths,ID,full XPATH on pretty much all input fields with no success. I've used selenium before and it works flawlessly but on amazon in particular it can't find the elements. For example the place order button (Je bestelling plaatsen in my language) can't be found nor clicked.
driver.find_element(By.XPATH, '//*[#id="turbo-checkout-pyo-button"]/span/input')
driver.find_element(By.ID, 'turbo-checkout-pyo-button')
driver.find_element(By.XPATH, '/html/body/div[4]/div[1]/div/div/div/div[2]/div/form/div/span/span/span/input')
How do I know which elements are clickable and direct to the intended page? If there is a way to tell please let me know. Thanks in advance
I'm not a selenium master but you can use the find_element_by_xpath function that returns an element object that can be clicked so:
element = driver.find_element_by_xpath('/html/body/div[4]/div[1]/div/div/div/div[2]/div/form/div/span/span/span/input')
element.click()
The problem was that the button was located in an iframe. Switching to the iframe and then pressing the button does the job. Found out through this question
driver.switch_to.frame("turbo-checkout-iframe")
directButton = driver.find_element(By.CSS_SELECTOR, '#turbo-checkout-pyo-button')
directButton.click()
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')
I am trying to save the same stuff with selenium in my Yandex account, the problem is that when I try to pass the code to click the button "save to Yandex disk", selenium pass me the message unable to locate the element.
Thats my code:
browser.find_element_by_xpath('/html/body/div[1]/div/div[2]/div[1]/div[1]/div/div[1]/div[3]/button[1]').click()
this is the page with the button "Save to yandex disk": https://yadi.sk/d/0ReZErv_cLl1-w
I read that u can also pass elements by name or by CSS selector, but when I try with firefox inspector to copy element, the browser gives me strange code.
Any suggestions?
..of course, the same error with or without logged into Yandex.
Thank you
You can use this XPath for detecting needed element:
//div[#class = 'folder-content content content_other content_dir']//button[contains(#class, "save")]
Use this xpath //*[contains(text(),'Save to Yandex.Disk')] to click "Save to Yandex.Disk" button
First thing is that we need to improve the xpath you are using to find the element we should use the xpath that is relative but in your case you are using the xpath that is absolute, I use the extension chropath in chrome to find the xpath of the element
Below mentioned is the chro path I would recommend you to use although the above two mentioned xpath can also be used
Let me know If you have any more queries, I can form a good xpath for you
//div[#class='folder-content__header']//span[contains(text(),'Save to Yandex.Disk')]
Below mentioned is one of the xpath I have used in my own project take a look maybe this can improve your horizon
//label[contains(text(),'Plant Code*')]//parent::div[#class='rb_Work_FieldContainer']//following-sibling::div[contains(#class,'rb_Work_FieldValueArea rb_Work_FieldValueArea_create ')]//textarea[#class='textarea']
I am interacting with svg elements in a web page.
I am able to locate the svg elements by xpath, but not able to click it, The error mentions that the methods like click(), onclick() are not available.
Any suggestions of how can we make it clickable ? please advice ?
Try to make use of Actions or Robot class
I am using Selenium WebDriver to do automated testing of a website. I have been successful in clicking through numerous menus and links to a point.
At one point the website I am working with generates links that look like this:
<U onclick="HourglassSubmitItem(document.all('PageName').value, '00000001Responsibility Code')">Responsibility Code</U>
I am trying to use the .click functionality of the webdriver to click this link with no success.
Using this:
page.find_element_by_xpath("//u[contains(text(),'Responsibility Code')]")
successfully finds the U tag above. but when I add .click() to the end of this xpath, the click is not performed. But it also does not generate an error. So, my question is can Selenium be used to simulate clicks on an HTML tag that is NOT an anchor () tag? If so, how?
I will also say that I do not have control over the page I am working with, so changing the to is not possible.
I would appreciate any guidance the Community could provide.
Thank You for you help,
Chris
Sometimes using JavaScript could solve the "clicking" issue:
element = page.find_element_by_xpath("//u[contains(text(),'Responsibility Code')]")
page.execute_script('arguments[0].click();', element)
You can prefer JavaScript in this case.
WebElment element = page.find_element_by_xpath("//u[contains(text(),'Responsibility Code')]")
JavaScriptExecutor executor = (JavaScriptExecutor)driver;
executor.ExecuteScript("arguments[0].click();", element);