can't click the checkout button on shopee using selenium - python

Trying click this shopee checkout button. can't continue to the next process. Here's the html element
html :
<button class="shopee-button-solid shopee-button-solid--primary " xpath="1"><span class="pcmall-cart_1FvSs2">checkout</span></button>
There is a my code:
def click(browser,element_css):
WebDriverWait(browser,60).until(
ec.visibility_of_element_located((By.CSS_SELECTOR, element_css)))
WebDriverWait(browser,60).until(
ec.element_to_be_clickable((By.CSS_SELECTOR, element_css))
)
browser.find_element_by_css_selector(element_css).click()
click(browser,'.shopee-button-solid')
wait.until(
ec.presence_of_element_located((By.CSS_SELECTOR,'.loading-spinner-popup'))
)
Error Code python selenium:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <button class="shopee-button-solid shopee-button-solid--primary ">...</button> is not clickable at point (984, 524). Other element would receive the click: <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 44 22" class="chat-icon">...</svg>
It doesn't work anymore and the button doesn't get clicked. Is there a way to solve this?

You could have used the explicitWait
check_out = WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,"")))
check_out.click()
So the code can be like
check_out = WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,"//*[#id="main"]/div/div[2]/div[2]/div/div[3]/div[2]/div[7]/button[4]")))
check_out.click()

Related

Click on Cancel Button in Print Document Message

I am trying to click on the cancel button which is in the print document in chrome. So here is the HTML
<cr-button class="cancel-button" aria-disabled="false" role="button" tabindex="0">
Cancel
</cr-button>
I have tried the following but did not work
driver.get(resume_url)
driver.maximize_window()
# Trial
driver.find_element_by_css_selector('cancel-button').click()
# Trial
driver.find_element_by_link_text('Cancel').click()
Nothing of these were successful and it returned the following error:
Message: no such element: Unable to locate element: {"method":"link text","selector":"Cancel"}
(Session info: chrome=89.0.4389.114)
Locating elements by link text only works for anchor elements.
https://selenium-python.readthedocs.io/locating-elements.html#locating-hyperlinks-by-link-text
To use the class name as a selector, you just append a period to the beginning. Does this work?
driver.find_element_by_css_selector('.cancel-button').click()

How to click on an element by partial_link?

this is ths html code :
<a href="https://www.decathlon.ca/fr/12547-cyclisme" xpath="1"> Cyclisme
</a>
And im trying to click on this element by this code but not working (Timeout) :
def click_cycling_menu(self):
cycling_menu_id = WebDriverWait(self.driver, 50)
cycling_menu_id.until(EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, "12547"))).click()
Can you use XPath contains functionality?
Feed this into find by xpath:
//a[contains(#href,"12547")]

Selenium click like on twitter

What is the most recent and up to date way to click "like" on a tweet using selenium?
From the css, it looks like I need to click on this:
<div aria-haspopup="false" aria-label="131310 Likes. Like" role="button" data-focusable="true" tabindex="0" class="css-18t94o4 css-1dbjc4n r-1777fci r-11cpok1 r-1ny4l3l r-bztko3 r-lrvibr" data-testid="like">
That is found on a profile page. My goal isn't to exactly like a tweet on a profile page but If I can figure this out, I'll be able to figure out what I actually want to do.
I have tried a bunch of ways but here are my most recent:
like_btn = (By.XPATH, ("//div[#data-testid='like', #class='css-18t94o4 css-1dbjc4n r-1777fci r-11cpok1 r-1ny4l3l r-bztko3 r-lrvibr']"))
like_btn = (By.XPATH, ("//div[#data-testid='like'"))
copy of Xpath:
like_btn = (By.XPATH, ("//*[#id='react-root']/div/div/div/main/div/div/div/div[1]/div/div[2]/div/div/div[2]/section/div/div/div/div[3]/div/article/div/div[2]/div[2]/div[4]/div[3]/div"))
Copy of full xpath:
like_btn = (By.XPATH, ("/html/body/div/div/div/div/main/div/div/div/div[1]/div/div[2]/div/div/div[2]/section/div/div/div/div[3]/div/article/div/div[2]/div[2]/div[4]/div[3]/div"))
The method then uses:
def like_user_tweets(self, user_tweets=UserStatuses.like_btn):
self.like_btn.click()
It looks like twitter recently revamped everything because even github code from only a year or less ago uses "HeartAnimation" class to find the like button but that doesn't seem to exist anymore.
The error: AttributeError: 'NoneType' object has no attribute 'click'
It is a button so shouldn't it be able to click?
How can I click the like/favorite button?
Error message:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted:
Element <div aria-label="394 Likes. Like" role="button" tabindex="0"
data-testid="like">...</div> is not clickable at point (539, 10).
Other element would receive the click: <div class="css-1dbjc4n r-1habvwh">...</div>
Solution:
browser = webdriver.Chrome()
infoq_url = 'https://twitter.com/infoqchina'
browser.get(infoq_url)
sleep(2)
like_buttons = browser.find_elements(By.XPATH, '//div[#data-testid="like"]')
like_btn = like_buttons[0]
like_svg = like_btn.find_element(By.TAG_NAME, "svg")
like_svg.click()
Reference:
btn_parent = btn.find_element(By.XPATH, "..") # find parent element.

Python Selenium find Button with innterHTML and click it

I'm trying to find the following button and click it:
<div id="subText" class="btn btn-success">Subscribe</div>
I already tried to find the button with the following:
driver.find_element_by_css_selector('div.btn.btn-success').click()
but I get the following error:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <div id="subText" class="btn btn-success">...</div> is not clickable at point (408, 513). Other element would receive the click: <div class="delete-overlay white" style="">...</div>
Is there a way to search only for the button with the "Subscribe" text and click it?
Edit:
I found out that the following element is blocking the button from beeing clicked:
<svg class="svg-inline--fa fa-spinner-third fa-w-16 fa-spin fa-4x" aria-hidden="true" data-prefix="fas" data-icon="spinner-third" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" data-fa-i2svg=""><path fill="currentColor" d="M456.433 371.72l-27.79-16.045c-7.192-4.152-10.052-13.136-6.487-20.636 25.82-54.328 23.566-118.602-6.768-171.03-30.265-52.529-84.802-86.621-144.76-91.424C262.35 71.922 256 64.953 256 56.649V24.56c0-9.31 7.916-16.609 17.204-15.96 81.795 5.717 156.412 51.902 197.611 123.408 41.301 71.385 43.99 159.096 8.042 232.792-4.082 8.369-14.361 11.575-22.424 6.92z"></path></svg>
Is there a way to wait/stop the script until the elemen/script is gone and continue?
I also tried to wait until the "Subscribe" button is visible but that didn't work:
sbutton = expected_conditions.presence_of_element_located((By.CSS_SELECTOR, 'div.btn.btn-success'))
WebDriverWait(driver, timeout_limit).until(sbutton)
As per the message <div class="delete-overlay white" style="">...</div> is overlapped so the script is not able to click on the <div id="subText" class="btn btn-success">Subscribe</div> button.
Here are the options to handle this situation.
1) Using JavaScript:
ele = WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "'div.btn.btn-success")))
driver.execute_script("arugments[0].click()",ele)
2) Scrolling to Element
ele = WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "'div.btn.btn-success")))
ele.location_once_scrolled_into_view # this will scroll to the element
ele.click()

How to click on radio button(I read previous questions) python?

I have the code
<div>
<input type="radio" id="grupo1" name="grupo1" name="ControlGroupSearchView2$AvailabilitySearchInputSearchView2$RadioButtonMarketStructure" value="OneWay" />
<label>One-way</label>
</div>
And I tried what other suggested to use
args["OW"] = "input[type='radio'][value='OneWay']"
WebDriverWait(self.browser, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, args["OW"])))
self.browser.find_element_by_css_selector(self.args["OW"]).click()
but I get error:
selenium.common.exceptions.TimeoutException: Message:
since it doesn't find the object.
Assuming there are no iframe elements on the page.
What I found working for radiobuttons is to click the corresponding label and not the input:
wait = WebDriverWait(self.browser, 10)
one_way = wait.until(EC.visibility_of_element_located((By.XPATH, "//label[. = 'One-way']")))
one_way.click()

Categories