Python grab element in scroll box - python

How can I grab an element in a scroll box based on the text?
I'd like to click the shoe " NAVY/NAVY/GREY (444)". I've tried
`color_code = '444' `
`driver.find_element_by_partial_link_text(color_code)`
Here's the source for the website I'm trying to navigate through
Highlighted is the element I'd like to grab and click()
Any help/insight would be appreciated.

Link text and partial link text only work on anchor tags <a>. Since your element is a <span> you might want to use css selector or xpath to locate it. If you specifically want to click on the shoe with that colour code, you can use driver.find_element_by_xpath("//span[contains(text(), color_code)] provided the page only has one shoe with that colour code.
You can also use find_elements_by_xpath method to get a list of all the shoes with that colour code and iterate over it to perform actions

try this :
driver.find_element_by_css_selector("span.btn-xs.btn-link.addProductColor").click

Related

Can't find the right XPATH for python locator

I write locators, need to find the checkbox by the text of the span element. Tried this one but didn't work
//span[text()='#1599064']/ancestor::div[#data-class-name='SourceView']/div/input
Please help
https://i.stack.imgur.com/Hljbi.png
With only this information is difficult, but if the text is static you can try to locate that one using the developer console. If you're on Chrome/Firefox press F12, then under the Elements tab (on chrome) click the exact element you would like to extract the XPATH selector, then right click and Copy > Copy Xpath.
I hope this can help you .

How to click a menu item from mobile based website in selenium Python?

So, I was doing some automation for Google Play Store(website from computer).
This is the element I am looking to click.
This is the menu which opens when we click the 3 dots on side of review. I have to click one of these 3 menu options then. I am not able to use .click() function on any of these 3 items.
All of these 3 span elements of menu are contained in a single div parent.
When I use
element = driver.find_element_by_xpath('/html/body/div[1]/div[4]/c-wiz/div/div[2]/div/div/main/div/div[1]/div[3]/div/div[2]/div[1]/div[2]/div/div[2]/div[2]/div/div/div/span[2]/div[2]')
element.click()
It gives:
ElementNotInteractableException: Message: Element <div class="uyYuVb oJeWuf"> could not be scrolled into view
I tried to click the span, and also its child elements like div which has display:flex also the last div child. But all of them gave the same exception. I know Play Store is mainly for mobile and therefore it is showing the properties of a mobile element. What is the appropriate way to click any of these 3 options then?
here is the link:
I don't think it is possible to click on a span like this one using selenium. However I think you should try getting the position of this span on the screen so you can click on it using a module like pyautogui :
import pyautogui
pyautogui.click(x=positionx, y=positiony)
This is the only solution I found and I hope you will not have to do it a lot of time in your program since it's repetitive and annoying (to find the x and y positions)

How to click an image given an Xpath in Selinum with Python?

So I have the HTML code:
enter image description here
How do I click this button? What is the Xpath for this one?
The xPath to that particular image is
/html/body/img
To click it
driver.findElement(By.xpath("/html/body/img")).click()
For xpath you need to have a path from top level upto this button.
Would look something like html\body\div\button [ just an example ].
You will have to check the whole page to navigate to that button using xpath.
Another better way could be using find element by class="auth-button positive" and then click() it

Finding elements after click using Selenium

I can't figure this one out.
I am working on this site and I have used selenium in Python to click on the first element under the class name "yellow showPopupUnder" (the main part of the screen where there are 20 yellow rows of information about houses).
After I get Selenium to click on that row it opens up and shows more information. I am interested in the part where there are 'checked' and 'unchecked' boxes. Those checked boxes are in a div like so:
<div class="v_checked">
And the unchecked boxes are in a div like so:
<div class="v_unchecked">
I have tried reaching them in a few ways:
driver.find_element_by_class_name('v_checked')
driver.find_element_by_css_selector(".v_checked")
driver.find_element_by_xpath("//div[#class='v_checked']")
I have also tried to use the absolute xpath. All of these don't work and I get a "NoSuchElementException: no such element: Unable to locate element"
Does anybody know how to retrieve the data from those boxes?
Thank you!
There is a iframe used that opens up and shows more Information where those Checkbox are shown. You have to navigate to that iframe. You can do something like this:
## switch to the iframe ##
driver.switch_to_frame(driver.find_element_by_id("ad_iframe_2_1_1731213"))
## then you can search your checkbox##
driver.find_element_by_class_name('v_checked')
## Switch back to the "default content" (that is, out of the iframes) ##
driver.switch_to_default_content()

How do I click the first link in a list using Selenium Webdriver

http://store.nike.com/us/en_us/pw/mens-nikeid-shoes/7puZoolZoi3
I am trying to click the first shoe listed in the store. I need to know how to reliably click the first shoe, as the store inventory changes daily, so I'm worried that if I write this myself without checking, the script could break when the shoe inventory changes.
Should I be using xpath or css_selector?
How do I do correctly do:
driver.find_element_by_css_selector("firstshoe").click()
The following CSS selector would match all products (shoes) on the page:
.grid-item.nikeid
And if you use driver.find_element_by_css_selector(".grid-item.nikeid").click() - you would click the first shoe on the page.
You can also use below XPath to find the first link in the grid
//*[contains(#class,'grid-item')]/a)[1]

Categories