Unable to locate element python selenium - Need to click this button - python

So, this button has no id/name and I've tried xpath, class name, CSS selector, etc
Here is the HTML code:
Thanks in advance.

Be sure to switchTo the iframe that contains this button! Then I think that this CSS path should work:
div.submit-and-reset-wrapper button.continue

You can try a kind of ugly hack:
get all the button/span elements
loop all the button/span elements until you find the text.
then click the element...
something like:
all_span_elements = driver.find_elements_by_tag_name("span")
for span_element in all_span_elements:
if "Begin Lesson" in span_element.text:
span_element.click()

Related

Cant click this button via xpath

I cant click this button neither class or full xpath
my cde:
#checkout page
driver.get("https://www.theathletesfoot.gr/pages/checkout/default.aspx?lang=el")
time.sleep(5)
driver.find_element_("/html/body/div[1]/div[3]/div[2]/div/div/section/form/aside/div[1]/div/div[1]/div/div[1]/div/label").click();
It appears you copied the XPath of the label, instead copy the XPath of the input right above the selected span in your screenshot and replace the XPath in the code.
The correct XPath should be
//*[#id="chkDisclaimer2"]

How to do double click on <a> tag using python selenium

I want to scrape the data on web site. But I have a problem, I want to click the a tag with double click. Who know about this? If you know this, help me, please.
My code:
<a href="#product-lists id='products'">
If you know about it, Please help me.
Thanks
path='//a[#href="{}"]'.format("#product-lists id='products'")
print(path)
from selenium.webdriver import ActionChains
source = driver.find_element_by_xpath(path)
action = ActionChains(driver)
action.double_click(source).perform()
Your href value looks really messed up but to double click an element by their href values use action builder and find the href value with that value.

How to find href through class name and click with selenium

I'm using Selenium with python to make a spider.
A part of the web page is like this:
text - <span class="sr-keyword">name</span> text
I need to find the href and click.
I've tried as below:
target = driver.find_element_by_class_name('_j_search_link')
target.click()
target is not None but it doesn't seem that it could be clicked because after target.click(), nothing happened.
Also, I've read this question: Click on hyperlink using Selenium Webdriver
But it can't help me because in my case, there is a <span class>, not just a simple text Google.
You can look for an element with class _j_search_link that contains text Wat Chedi Luang
driver.find_element_by_xpath('//a[#class="_j_search_link" and contains(., "Wat Chedi Luang")]')
driver.find_elements_by_partial_link_text("Wat Chedi Luang").click()
I think you didn't find right element. Use CSS or Xpath to target this element then click it, like:
//a[#class='_j_search_link']
or
//a[#class='_j_search_link']/span[#class='sr-keyword']

Facebook post_box element. I cant find element by xpath

Facebook post_box element. I cant find element by xpath
Hi,
I learn to write automation test scripts in Selenium Webdriver with Python. I will make "Facebook Poster script". After login i wanna click in SendBox and sent some text, but i cant identyfing it with Xpath. Firebug not help mi with this. Thx for help.
Something like this:
After login
newpost=driver.find_element_by_xpath("i dont know correct xpath")
newpost.click()
newpost.send_keys("Hello!")
newpost.submit()
Xpath from Firebug not working
newpost = driver.find_element_by_xpath("/html/body/div[1]/div[2]/div[1]/div/div[2]/div[2]/div[2]/div/div[3]/div/div/div/div[2]/div[1]/div/div/div/div[2]/div/div[1]/div[1]/div[2]/div/div/div/div/div/div[2]/div/div/div/div")
First of all, never use absolute xpath - it's costly to maintain and looks just horrible.
As I understand, you need to click on input field with the placeholder 'what's on your mind'. Then you can get use of 'data-testid' attribute with value 'status-attachment-mentions-input'.
If you really need to use xpath, try this:
"//[#data-testid='status-attachment-mentions-input']". You can also use css selector and find yo element like this:
inputField = driver.find_element_by_css_selector("[data-testid='status-attachment-mentions-input']")
Correct solution:
newpost = driver.find_element_by_css_selector("[name='xhpc_message']")
newpost.click()
newpost.send_keys("Hello!")
newpost.submit()
#GVi thx for help

How to send keys to a difficult element in selenium (Python)

I am trying to click a small button, which has no "ID" or "Name", on a website. The only unique identifier is onclick, which is as follows:
onclick="submitForm('DefaultFormName',1,{'param1':'HXCTIMECARDACTIVITIESPAGEXgm7J5oT','serverValidate':'1uCdqvhJe','param2':'',event:'details|1'});return false;"
However, another button on the page has the following onclick:
onclick="submitForm('DefaultFormName',1,{'param1':'HXCTIMECARDACTIVITIESPAGEXgm7J5oT','serverValidate':'1uCdqvhJe','param2':'',event:'details|2'});return false;"
The only difference is a 1 vs. a 2 in the middle of the code. I tried to use a "find_element_by_css_selector" with the following code but it didn't work:
driver.find_element_by_css_selector(".x1p[onclick*='details|1']").click()
Another option would be selecting the preceding element, with the following code:
precedingbutton = driver.find_element_by_name('B22_1_6')
And then sending tab and then enter. However, after I send Tab, I don't know of a way to send Enter without assigning the Send_Keys command back to the preceding box, which deselects the button I want.
Let me know if you can help!
If you can locate the parent, you can locate the child, either with xpath or the nth-child css selector, relative to it.
Edit in response to comments:
Assuming by "2 elements away" you mean it is a sibling preceding the target, try something like td[name="B22_1_6"] + td + td. This is the sibling selector.
You can do it easily by
driver.find_element(By.XPATH, 'your xpath').click()
For finding the xpath , just inspect the button with firebug, and in html tab right click on selected element and click on Copy XPath.
Hope it will help you.

Categories

Resources