How To Click On A Search Engine Result If It Matches The Searched Value
I'm new to selenium. I'm taking user input and based on that, I'm searching it in duckduckgo. I want, if the input value matches the search result weblink, the code should click on
Solution 1:
Actually I am from Java background but still if you could convert my two lines of java code into python you would be able achieve it
Your code :
for link in b: url = link.get_attribute('href') if any(dom in url for dom in list): link.click() break
Instead of link.get_attribute, Convert the above code as below
In Java we have .getText() method to get the Text.
So try to get the text which your looking for using python as below(I used Java)
link.getText() store thisin a variable
For ex asinJava : String str = link.getText()
And then here comes your if Condition
use your contains method as in python the below one is in Java
if(str.contains("Mitchell Centre, Darwin CBD, 0800"))
link.click()
break
This code is working fine for me.
Post a Comment for "How To Click On A Search Engine Result If It Matches The Searched Value"