New answers tagged

0

This can be done with extra filtering in Python, but the usual straightforward way is to add an extra condition to your CSS selector: all_items = driver.find_elements_by_css_selector("ul > li") versus: filtered_items = driver.find_elements_by_css_selector("ul > li.myclass") where . is a class selector.


0

Python has a feature called List Compreenshion, aimed at creating lists from other lists, after applying some processing on each element. 1 - Find the li elements: li_items = driver.find_elements_by_class_name("li") 2 - Filter in only element with a given class: li_items_with_class = [ item for item in list_items if "my_class" in item.get_attribute("...


0

I don't know the exact answer but maybe can help find the solution. Have you tried finding out if this is actually the correct window handle? You could try debugging by: Counting the number of window handles Opening the last window handle in stead of exactly [1] Reading the DOM of all window handles to see what is found by executing this script over each ...


0

Did you try to read the documetation for the Selenium Python package? See: https://selenium-python.readthedocs.io/navigating.html Code example from the documentation: from selenium.webdriver.support.ui import Select select = Select(driver.find_element_by_name('name')) select.select_by_index(index) select.select_by_visible_text("text") select....


0

The idea here is to apply the findAll - filter - extract pattern. Find all: ng_scopes = driver.find_elements_by_class("ng-scope") Filter: ng_scopes_with_status_one = [ng_scope for ng_scope in ng_scopes if ng_scopes.find_element_by_css_selector(".col-xs-8 span").text == "1"] Extract: ng-repeat_value = ng_scopes_with_status_one[0].get_attribute("ng-...


2

There is an animation when you land the page. Before using the element, you have to wait for it to be clickable. element = WebDriverWait(driver, 20).until( EC.presence_of_element_located((By.ID, "departure")))


2

I don't think you need to iterate through them. Just target the correct element, your xpath could look like this: //li[@data-cy='roundTrip'] One of the problems with your current xpath is you're trying to find an 'a' element, where the fake radio buttons are actually 'li' elements.


2

You first have to open the menu, by clicking on the From City text, using ID. driver.find_element_by_id("fromCity").click() Then you can query the autocomplete, but fixing the locator you used (only one class is necessary): driver.find_element_by_css_selector(".react-autosuggest__input--open")


1

I think by class name only takes a single class not multiple. You could try a css selector to find elements with two classes: element = driver.find_element_by_css_selector(".react-autosuggest__input.react-autosuggest__input--open") Or just only use one of the classes instead of both.


0

You should try looping over the list you created. z is a list, and when you don't loop over the list it tries to run only once. for value in z: driver.find_element_by_xpath("//div[text()='Maximum 5000 Names']/..//textarea").send_keys(value) time.sleep(2)


Top 50 recent answers are included