python selenium click on button
Remove space between classes in css selector: driver.find_element_by_css_selector(‘.button .c_button .s_button’).click() # ^ ^ => driver.find_element_by_css_selector(‘.button.c_button.s_button’).click()
Remove space between classes in css selector: driver.find_element_by_css_selector(‘.button .c_button .s_button’).click() # ^ ^ => driver.find_element_by_css_selector(‘.button.c_button.s_button’).click()
You need to access the page_source property: from selenium import webdriver browser = webdriver.Firefox() browser.get(“http://example.com”) html_source = browser.page_source if “whatever” in html_source: # do something else: # do something else
Just for anyone else who’s looking for an answer in Ruby, Python, and C# bindings (Selenium 2.33.0). Note that the actual keys to send depend on your OS. For example, Mac uses CMD + T, instead of Ctrl + T. Ruby require ‘selenium-webdriver’ driver = Selenium::WebDriver.for :firefox driver.get(‘http://stackoverflow.com/’) body = driver.find_element(:tag_name => ‘body’) body.send_keys(:control, ‘t’) … Read more
This error message… DeprecationWarning: executable_path has been deprecated, please pass in a Service object …implies that the key executable_path will be deprecated in the upcoming releases. This change is inline with the Selenium 4.0 Beta 1 changelog which mentions: Deprecate all but Options and Service arguments in driver instantiation. (#9125,#9128) Solution With selenium4 as the … Read more
In a word, no. It’s not possible using the Selenium WebDriver API. This has been discussed ad nauseam in the issue tracker for the project, and the feature will not be added to the API.
You want just .text. You can then verify it after you’ve got it, don’t attempt to pass in what you expect it should have.
Don’t know if you resolved this problem, but I have just resolved the same issue from the other side. It appears Selenium and Firefox have difficulty talking to each other – I suspect Firefox ‘evolve’ changes over a number of releases, so backward and forward compatibility are not always guaranteed, and incompatibility always seems to … Read more
Use findElements instead of findElement. findElements will return an empty list if no matching elements are found instead of an exception. To check that an element is present, you could try this Boolean isPresent = driver.findElements(By.yourLocator).size() > 0 This will return true if at least one element is found and false if it does not … Read more
Your suggested solution only waits for DOM readyState to signal complete. But Selenium by default tries to wait for those (and a little bit more) on page loads via the driver.get() and element.click() methods. They are already blocking, they wait for the page to fully load and those should be working ok. Problem, obviously, are … Read more
Try element.getAttribute(“value”) The text property is for text within the tags of an element. For input elements, the displayed text is not wrapped by the <input> tag, instead it’s inside the value attribute. Note: Case matters. If you specify “Value”, you’ll get a ‘null’ value back. This is true for C# at least.