Sign in
Hey Guys,
Pretty simple question here but I'm having trouble with it for some odd reason. What is the best way to "grab" this button in selenium (using python but a generalized solution would work as well). Its a button, but its html is not a button which means this has not been working for me.
driver.find_element(By.XPATH, '//button[text()="Sign in"]')
Any help would be great, thanks!
You should be able to access it using the a tag instead of button like this
driver.find_element(By.XPATH, "//a[contains(text(), 'Sign in')]")
Selenium docs on locating elements by XPath
and
A good SO answer to help locate an element that contains given text
Related
I'm new in python scripting. I'm trying to develop a bot that can access websites and work on it with Selenium.
I can do basics things like enter text in a search bar but I am blocked with a popup.
I try to access the popup element but I can't. It seems the element I want to reach are on a "modal" popup.
I have tried many things, I can access to the "modal"popup:
popup = self.__driver.find_element_by_xpath("//div[#id='modal']")
but I can't access to any element right under the revious one:
element = self.__driver.find_element_by_xpath("//div[#id='region-modal-right-panel']")
Can somebody help me with this problem? Thank you in advance for your help!!
If my explanations wasn't clear, do not hesitate to ask for mor details.
EDIT: link to the popup: https://app.libertex.com/products/currency/EURUSD/#modal_newInvest_EURUSD
The popup
Trying to automate a YouTube search as I'm learning python automation, however I've come across a problem. I can't figure out how to automate clicking the "I agree" on the popup, hoping someone can send a solution
You can find the element using xpath and click on it with the click() method: https://pythonspot.com/selenium-click-button/
To switch to the iframe popup
driver.switch_to.frame("iframe")
//("iframe" for this specific example, otherwise put id of the iframe there)
driver.find_element_by_xpath('//*[#id="introAgreeButton"]/span/span').click()
To switch back to main frame
driver.switch_to.default_content()
browser.switch_to_default_content()
browser.switch_to.frame(browser.find_elements_by_tag_name('iframe')[0])
browser.implicitly_wait(1)
browser.find_element_by_id('introAgreeButton').click()
browser.switch_to.default_content()
I'm using 'browser' instead of 'driver' here.
I am trying to click the search button in this link here
I would like to click the search button and then download all URL's on the next page but currently it is finding monthly list
The link below takes you to a screenshot of my code where it outputs the monthly list button instead of searcj/
Python code selenium
Welcome to Stack Overflow!
You can use the .click() method to click an element object, and the .find_element_by_xpath() method to find the element. I've located that the element's full XPATH is /html/body/div/div/div[3]/div[3]/div/form/fieldset/div[5]/input[2].
You can implement all the pieces together like so:
driver.find_element_by_xpath("/html/body/div/div/div[3]/div[3]/div/form/fieldset/div[5]/input[2]").click()
if you are starting I recommend you using some extension to help you find the xPath of the elements.
I used Xpath Helper from Chrome, but you can use any other.
The Xpath of the Search button is:
/html[#class='js']/body/div[#id='idox']/div[#id='pa']/div[#class='container'][2]/div[#class='content']/div[#class='tabcontainer']/form[#id='weeklyListForm']/fieldset/div[#class='buttons']/input[#class='button primary']
After you have the XPath you can use it in the selenium driver to find the elements.
This can be enough, but I recommend you to learn in depth how this works to know exactly what it is doing.
I try to press a button using selenium. How do I click on a particular button using several conditions? (https://ibb.co/cJZxD7b) describing image
I have already tried something like this //span[text()=1.01], but what if webpage have few buttons with the same text.
wait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[text()='45.00 7.75 1.04'] and //span[text()=1.04"))).click()
I expect to click on particular button
You can try with xpath
//span[#class='stn-val']
But it would probably be the best if you shared more of the HTML code because now I'm only guessing based on what I see.
Also, are you getting any error messages?
UPDATE:
Based on HTML posted in comments, use this selector:
//div[#class="st-col-bet-container"][2]/ul/li[3]/span
For tips on xpath selectors, see here.
I have one button from one LinkedIn page with this code:
<div class="primary-action-button"><a class="primary-action label" href="/requestList?displayProposal=&destID=39959446&creationType=DC&authToken=Yr4_&authType=OUT_OF_NETWORK&trk=vsrp_people_res_pri_act&trkInfo=VSRPsearchId%3A2998448551382744275729%2CVSRPtargetId%3A39959446%2CVSRPcmpt%3Aprimary">Send InMail</a></div>
Is there any way to click on an element just by its href link? Thanks
Using selenium you could use the following code:
driver.find_element_by_link_text("Send InMail").click()
The above answer driver.findElement(By.linkText("Send InMail")).click(); is in Java. In python, use find_element_by_link_text:
driver.find_element_by_link_text('Send InMail').click()
or something like this is sometimes helpful
driver.find_element_by_partial_link_text('Send').click()