Thanks for letting me ask my questions here. I am new to Selenium and XPath, just trying to scrape a not-so-simple website using Python.
My questions are:
The specific question: I have a HTML file that looks as follows and want to extract the 'data-testid="qs-select-make"' element (in the end, I want to use selenium to update the drop-down menu)
For the life of me, I do not get it to work....
<div class = "a">
<div class = "ab">
<div class = "abc">
<div class = "abcd">
<select class="tya6p HaBLt A4yQa q0MnL" placeholder="Any" data-testid="qs-select-
make"><option selected="" value="">Any</option>
Using the google chrome web developer I already found the "correct" (albeit not very nice path) seems to be
[@id="root"]/div/div/article[1]/section/div/div[2]/div[1]/div[1]/div/select
Still, the following code, attempting to insert the make "Audi" into the drop-down menu, fails with an Invalid Selector Exception:
make_string = "//select[//*
[@id='root"]/div/div/article[1]/section/div/div[2]/div[1]/div[1]/div/select]option
selected[text()='{}']".format("Audi")
driver.find_element("xpath", make_string).click() #use selenium to click the button
Does anyone know what I am doing wrong, and of a nicer way to do it?
Regarding question 2, the resource. So far I have used:
Use the below xpath
to identify the element. Please add syncronisation
time as well.
driver.find_element("xpath", "//select[@data-testid='qs-select-make']//option[text()='{}']".format("Audi")).click()